DEV Community 👩‍💻👨‍💻

Sanat Kumar Mohanta
Sanat Kumar Mohanta

Posted on

JavaScript Basics

Truthy and Falsy values in javascript :

In javascript falsy values are defined as :

  1. when the condition is false 2.when value = 0
  2. empty string is also a falsy value
  3. Null is a falsy value
  4. Undefined is also falsy
  5. NaN is also falsy

In javascript truthy values are defined as:

  1. When the condition is true
  2. Any numbers (negative or positive)
  3. Any string including single white space 4.[] an empty array
  4. {} an empty object
  5. anything that is not falsy will be truthy

                  **Null vs undefined** 
    

undefined

:
It means a variable is declared, but no value has been assigned a value.
For example,
var demo;
alert(demo); //shows undefined
alert(typeof demo); //shows undefined

null :

Whereas, null in JavaScript is an assignment value. You can assign it to a variable.
For example,
var demo = null;
alert(demo); //shows null
alert(typeof demo); //shows object

double equal (==) vs triple equal (===) in javascript

== in JavaScript is used for comparing two variables, but it ignores the datatype of the variable. === is used for comparing two variables, but this operator also checks datatype and compares two values.

Top comments (0)

Become a Moderator Can you help us make DEV a better place?

Fill out this survey and help us by becoming a tag moderator here at DEV.