Conditional Statements and Loops
Pop Up Box
Assignment operators Assignment operator assigns a value to left operand from right operand. The equal (=), assigns the value of its right operand to its left operand. In example x = y assigns the value of y will be assigned to x. There are compound assignment operators which are explained below.
What is the difference between == and ===?
1.Comparison operators — operators that compare values and return true or false. The operators include:
a.Less than (<) — returns true if the value on the left is less than the value on the right, otherwise it returns false.
b. Greater than (>) — returns true if the value on the left is greater than the value on the right, otherwise it returns false.
c. Less than or equal to (<=) — returns true if the value on the left is less than or equal to the value on the right, otherwise it returns false.
d. Greater than or equal to (>=) — returns true if the value on the left is greater than or equal to the value on the right, otherwise it returns false.
e. Equal to (===) — returns true if the value on the left is equal to the value on the right, otherwise it returns false.
f. Not equal to (!==) — returns true if the value on the left is not equal to the value on the right, otherwise it returns false.
2)Logical(Boolean) operators — operators that combine multiple boolean expressions or values and provide a single boolean output. The operators include:
a. && (and) — This operator will be truthy (act like true) if and only if the expressions on both sides of it are true.
b. || (or) — This operator will be truthy if the expression on either side of it is true. Otherwise, it will be falsy (act like false).
c. ! (not) _this returns opposite of the input.
Bitwise operators treat its operands as a group of 32-bit binary digits and perform actions. But, the result is shown as a decimal value.
Bitwise AND & returns 1 if both operands are 1 else it returns 0.
Bitwise OR | returns 1 if either of the corresponding bits of one operand is 1 else returns 0.
Bitwise XOR ^ returns 1 if the corresponding bits are different and returns 0 if the corresponding bits are the same.
Bitwise NOT ~ inverts the bit( 0 becomes 1, 1 becomes 0).
Bitwise SHIFT operators:
LEFT SHIFT <<: I.e. shifts the elements to the left and insert 0 in the gap formed. For example, 15<<1 or 1111<<1 implies 1110 or 14.
RIGHT SHIFT >>>: It is just the reverse of LEFT SHIFT, that is 15>>>1 or 1111>>>1 implies 0111 or 7.
SIGNED RIGHT SHIFT >>: i.e. it returns the signed right shift. For example, 1111>>1 or 0111 or 7. Since the fourth bit is 0, positive.
The + operator, += operator used to concatenate strings.
Given that text1 = "Good ", text2 = "day", and text3 = text1 + text2 then text3=goodday.
Nan function :
Definition and Usage
The isNaN() function checks whether a value is a valid number
This function returns true if the value equal to Nan result . Otherwise it returns false.
This function is different from the.isNaN() method.
The global isNaN() function, converts the tested value to a Number, once conversion is done then tests it.
isNaN(0 / 0) //true
Infinity function :
Division by 0 gives you another special value:
You can’t perform any operation on positive and negative infinity against each other:
> Infinity – Infinity
It is still infinity:
>Infinity + Infinity
>5 * Infinity
Yes, ‘?’ is the ternary operator. It is same as in C. That is, (condition?true:false).For example, (12>2?1:0) returns 1.
Explain the use of 'typeof' operator.
The uses of typeof operator are listed below:
Typeof can be used to check whether a variable exists and it has a value.
The typeof operator used for checking that a value is neither undefined nor null.
It differentiate between objects and primitives.
It tells What is the type of a primitive value.
typeof check whether a value is a function.