








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









A JavaScript global variable is declared outside the function or declared with window object. It can be accessed from any function. Let’s see the simple example of global variable in JavaScript.
To declare JavaScript global variables inside function, you need to use window object. For example:
When you declare a variable outside the function, it is added in the window object internally. You can access it through window object also. For example:
JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
There are five types of primitive data types in JavaScript. They are as follows:
String represents sequence of characters e.g. "hello" Number represents numeric values e.g. 100 Boolean represents boolean value either false or true Undefined represents undefined value Null represents null i.e. no value at all
Play Videox
== Is equal to === Identical (equal and of same type) != Not equal to !== Not Identical
> Greater than >= Greater than or equal to < Less than <= Less than or equal to JavaScript Bitwise Operators The bitwise operators perform bitwise operations on operands. The bitwise operators are as follows:
& Bitwise AND (10==20 & 20== | Bitwise OR (10==20 | 20== ^ Bitwise XOR (10==20 ^ 20== ~ Bitwise NOT (~10) = - << Bitwise Left Shift (10<<2) = 40 >> Bitwise Right Shift (10>>2) = 2 >>> Bitwise Right Shift with Zero (10>>>2) = 2 JavaScript Logical Operators The following operators are known as JavaScript logical operators.
&& Logical AND (10==20 && 20==33) = false || Logical OR (10==20 || 20==33) = false ! Logical Not !(10==20) = true JavaScript Assignment Operators The following operators are known as JavaScript assignment operators.
JavaScript If statement It evaluates the content only if expression is true. The signature of JavaScript if statement is given below.
Let’s see the simple example of if statement in javascript.
value of a is greater than 10 JavaScript If...else Statement It evaluates the content whether condition is true of false. The syntax of JavaScript if-else statement is given below.
if(expression){
//content to be evaluated if condition is true
}
else{
//content to be evaluated if condition is false
document.write("a is even number");
}
else{
document.write("a is odd number");
}
The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript.
It evaluates the content only if expression is true. The signature of JavaScript if statement is given below.
Let’s see the simple example of if statement in javascript.
Let’s see the example of if-else statement in JavaScript to find out the even or odd number.