JavaScript is a core versatile website designing language that helps the website makers in making a interactive website without any hard and fast rule. Those who want to embrack their career into web should definitely learn JavaScript. But mastering JS is only possible when you have joined an ideal web development institute in Delhi. Institutes like WDI prepares students in each and every important concepts of JS. This blog brought to you by one of the students at WDI who is talking about the building blocks of JavaScript.
Hello readers, this is Prabjoon, I’m attending JS classes under my web development training in Delhi at WDI.
Variables
We can start the list with variables because the heart of JavaScript lies the concept of Variables. Variables are like containers to store or hold the data as well as to work on the manipulation of the data.
There are some examples to declare the variable through “Var” “Let” and “Const”, variables can be stored multiple times in a string.
Var
The var variable had been used in JavaScript language from 1995 to 2015.
We store the variable by denoting x, y and z
Var x = 1;
Var y = 4;
Var z = (x+y);
console.log(z);
The answer will be “5”.
As we saw earlier, we are declaring the variables multiple times to find the final results of our variable. In this example X is storing the value of 1, Y is storing the value of 4 and Z is storing the value of 5.
Let
This variable is used to declare the variable, but it cannot be Redeclared in the same manner, it will not be declared accidentally in a function.
Let x = “Prabhjoon”;
Let x = “Harmeet”;
In JavaScript with the variable let, you cannot redeclare the variable x again. but y can declare the variable in “Var”.
Const
Const variable cannot be Reassigned and Redeclared, It has block scope, So we can only change the element of the constant array or the constant object.
Strings
Let x = “Paramjeet”;
Strings show the format with double inverted commas, “ “, whatever comes in between these commas will do the function accordingly.
Number
Let Quantity = 34;
It shows the number in a variable in a very simple format.
Null
Let number = null
In JavaScript the value null stands for an empty or unknown value.
Control Flow Statement
Control flow statements allow developers to control the order in which their code is executed. Key constructs include if statements, switch statements, and loops (for, while). These are essential for creating dynamic and responsive applications.
Examples to know the structure of the flow statement
let hour = 12;
if (hour < 12) {
console.log("Good morning!");
} else {
console.log("Good afternoon!");
}
As you can see we are using the if statement to make the code run as per the JavaScript language, it gives you the result as per the condition, if the time is less than 12 it gives you Good Morning else Good Afternoon.
Functions
Functions facilitate code organization, reusability, and modularity. Functions can take parameters and return values, adding to their versatility.
Please have a look at our example to understand the basic syntax of a function
function() {
}
At first, you need to write the function like this “function” After that you will see a “()” curly bracket beside the function, you can pass the parameter in it and see the direct result in the console, after that in the “{}” Parenthesis feel free to write your code.
Write this example in your visual editor and see the changes in a function
function greet(name) {
return "Hello, " + name + "!";
}
The console.log will show the structured answer will be like this
let greeting = greet("John"); // "Hello, John!"
These fundamental concepts provide the foundation for more advanced topics and empower developers to create dynamic and engaging web applications. As you delve deeper into JavaScript, you'll discover its rich ecosystem and the multitude of libraries and frameworks that further enhance its capabilities. In order to get your hands set strongly on this language, it is important to attending classes at JavaScript institute in Delhi.