An overview of intermediate javaScript concepts

Jahed Sabbir
Nov 5, 2020

JavaScript Truthy and Falsy

As well as a type, each value also has an inherent boolean value, generally known as either truthy or falsy. Today I’m talking about some JavaScript truthy or falsy concepts.

Some of value in javascript are always falsy as that,

  • false
  • 0 (zero)
  • '' or "" (empty string)
  • null
  • undefined
  • NaN

Some value are always truthy

  • [] empty array
  • {} empty object
  • '0' only 0(zero) is falsy but '0'(zero) under the string is truthy.

Null vs Undefined

  1. If you’re declare a variable but you do not set the value. At that moment javascript throw an error undefined

2.You write a function with two parameter num1 and num2 and you console.log(num1 + num2) under the function. But you don’t have return any value.Then the javascript show result undefined.

3.You declare a object and the object name is officer={name:"Jahed Sabbir" , Age=25} then you wish to get the officer number console.log(officer.number)but the number property is not set under the object.So, the result show undefined.

javaScript Double equals(==) vs Triple equals(===)

Sometimes we are check any variable using Double eqals in javaScript.Double Equals((==) is check only variable value.

Double equals check only variable value do not check value type .But Triple equals check value and type. It is a main different in double equals(==) and triple equals(===).

Calculate factorial of a number using for loop

The factorial function (symbol: !) says to multiply all whole numbers from our chosen number down to 1(one). like this:

  1. 10! = 1*2*3*4*5*6*7*8*9*10
  2. 5! = 1*2*3*4*5

--

--