Write about the JavaScript's basic grammar and types
A machine independent high level language which is known as JavaScript and being update and maintained by the ecma script, runs on browsers and even on the server. Programming is list of instructions which do runs linearly, we can say that grammar is the foundation of the language, and programming languages are built on the sets of the rules called syntax of the language. It is important to understand these rules while pursing your training with JavaScript course in Delhi.
Grammar of the JavaScript
We can understand the grammar of the JavaScript as:
Variables declaration
Variables are the containers which is used to store the data, in JavaScript we can define variables by using such keywords: var, let, const. We can store different types of data into the variables of JavaScript such as:
String: a string type of data can include the sequences of characters, spaces, numbers or punctuations.
Numbers: can only store numbers.
2. Expressions
An expressions is the combination of number, string and values to generate an output. And an expression is being evaluated from right to left direction while execution of the code. Let’s see an example of it:
let a = 10;
let b = a + 15;
In this above example, the right hand side values will be evaluated and then being stored into the left hand side variables.
3. Arithmetic
There are basically five types of arithmetic operators in the javascript to evaluate the math expressions, they are such as:
+, -, *, /, %
Let’s see an example:
var myNumber = 10 + 2;
console.log(myNumber);
4. Booleans
Booleans are typed of variables in JavaScript which can be used to store true or false.
Let’s see an example:
var myBooleans = true
console.log(myBooleans)
5. Comparisons
Comparisons operators are used to compares the values in JavaScript, there are seven kind of ways to compare to compare the data, all of them are listed here:
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
!= Not equal to
== Equal to
=== Strict equal to
There is a difference between equal to and strict equal to comparisons,
equal to: will only compare the data value of the variables not the type of the values.
Let’s see an example:
let a = 10;
let b = “10”;
if ( a == b ) {
console . log ( “ Matched ” ) ;
}
else {
console . log ( “ Does not match ” ) ;
}
In the above code, the output will be “Matched” because they both have the same values.
Strict equal to: it will compare the data as well as the data type of the values.
Let’s see an example:
let a = 10;
let b = “10”;
if ( a === b ) {
console . log ( “ Matched ” ) ;
}
else {
console . log ( “ Does not match ” ) ;
}
In the above code, the output will be “Does not match” because they both have the same values but does not have the same data type and the strict equal to checks the both while comparing.
Check some useful web design courses and pick up the one that suits the most for making career in this web industry.
6. Undefined
If a variable is being declared but it’s value is not defined then it will hold the value as undefined, and when a variable is given the value the it is called initialization of the variable. And if the variable is only declared then it is known as declaration of the variable. Let’s see the example of them here:
Declaration:
let a; // here the variable is declared but not defined by the value
Initialization:
a = 10;
So these are some of the basic grammar rules and types of the JavaScript that a beginner can learn and understand. There is a 18 months web design course in Delhi and it is a complete full-stack web development course that gives complete understanding of all the website designing and development languages including JavaScript.
Last updated