Ten simple topic about JavaScript

Md Shahadat Hossain
2 min readMay 8, 2021

Undefined vs Null:

When we get a value as undefined? There are so many reason for getting an undefined value. Some of them are

  • If we declare a variable without assigning a value. Then it’s value is undefined. Example : let num; console.log(num) // output = undefined.
  • If a function will not return any value then after calling the function it will return undefined.
  • If we don’t pass the value of the arguments of a function then it’s result is undefined.
  • If we want to read any property of an object which is not exist in that object then its value will undefined.
  • If any one set undefined as the value of any variable.

Now what about null? The value null is written with a literal null. null is not an identifier for a property of the global object, like undefined can be. The typeOf null is an object but undefined itself is a type. Null represent the absence of any object value.

Double equal(==) vs triple equal(===):

Double or triple equal is used for condition check. There is a little difference between double and triple equal. Double equal don’t check the data-type it only check the data but triple equal check the data-type also. For example : let num = 3, let str = ‘3' if we want to check num and str are equal or not then double equal will return true but triple equal return flase. Because one data-type is number and another data-type is string. So triple equal is more specific than double equal.

--

--