Primitive Values
There are 7 Primitive data types. They are:
- Number
- String
- Boolean
- Undefined
- Null
- Symbol
- BigInt
Example:
console.log(typeof "Sawda Hoque"); //output, "string"
console.log(typeof 12); //output, "number"
console.log(typeof true); //output, "boolean"
console.log(typeof null); //output, "object"
console.log(typeof undefined); //output, "undefined"
Ternary Operator
Ternary Operator is the smallest way for checking conditions. In ternary operator conditional checking using a question mark (?) and a colon (:).First of all, we write the condition, num>6 then we should use a question mark (?), then we write the code if the condition is true, then we should use a colon (:), then we write the code if the condition is false. We can use nested conditions in the ternary operator.
const number1 = 6;
const number2 = 10;
const largeNumber = number1 > number2 ? number1 : number2;
console.log(largeNumber); // output, 10
Double Equal(==) vs Triple Equal (===)
In JavaScript two double equal(==) compare the values. If the value is equal, return true. But triple equal compares(===) the values and compares the data type. If the value is equal and the type is equal, then return true, otherwise, return false.
console.log(5 == "5"); // output, true
console.log(5 === "5"); // output, false
console.log("5" === "5"); // output, true
isNaN() Method
isNaN() Method returns true if the argument is NaN, Otherwise it returns false.
Spread operator
Spread operator or(...) three dots are used for array expression or string to be expanded or an object expression to be expanded in places. You can copy all the elements of an array, all the properties of an object, and all iterable of the string.
const numbers = [9, 10, 15, 99, 22];
console.log([...numbers]); // output, [9, 10, 15, 99, 22]
console.log([...numbers, 55]); // output, [9, 10, 15, 99, 22,55]
IIFE
IIFE full meaning โ Immediately Invoked Function Expression
IIFE function is an anonymous function and the function will call Immediately. We canโt call the IIFE function another time.
(function (){
console.log(2+3);
})(); // output: 5
Top comments (0)