DEV Community

Sawda Hoque
Sawda Hoque

Posted on

Some Basic JavaScript Concepts .

Primitive Values

There are 7 Primitive data types. They are:

  1. Number
  2. String
  3. Boolean
  4. Undefined
  5. Null
  6. Symbol
  7. 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"

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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]

Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)