Articles → JavaScript → Type Coercion In JavaScript

Type Coercion In JavaScript






Scenario




  1. Use the === operator.
  2. Type coercion.

Type Coercion




  1. The integer value of false is 0.
  2. The integer value of true is 1.

Example


var boolean = true;
var integer = 1;
var booleanInt = Number(boolean); // Type Coercion

if (integer == booleanInt)
    alert("Equal");
else
    alert("Not Equal");

Try It




Posted By  -  Karan Gupta
 
Posted On  -  Sunday, January 15, 2017

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250