Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

difference between == and === in javascript

0 == false   // true
0 === false  // false, because they are of a different type
1 == "1"     // true, automatic type conversion for value only
1 === "1"    // false, because they are of a different type
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false
Comment

Difference Between =, == And === In JavaScript

var number = 100;  // Here number variable assigned using = 

if (number == 100)
  // Here Comparision between two values using ==.
  // This will not check datatype irrespective of datatype it will do comparision  
  console.log("Both are equal");

else  
  console.log("Both are not equal");

if(number === "100")  //Here Comparision between two values using ===.
  // This will check datatype if it is same then it will do comparision otherwise it will go to else part  
  console.log("Both are equal");

else  
  console.log("Both are not equal");

/*
Output will be :- 
	Both are equal
	Both are equal
*/
Comment

== vs === in javascript

(==)[double equal]compare the only DATA , not TYPE (0(int) == "0"(string)) ==> true) ==> not checking DATATYPE 
(===)[triple equal ] compare strictly  DATA and TYPE (0 === "0" ==> false) ==> checking the DATATYPE first
Comment

difference between =, == and === in javascript

/*
= operator in javascript is called as assign operator. It is used to assign
value to a variable, it is used as: */
variable = "value"
/*      ^^^
here, as you can see, it is saying that variable should be assigned(=) the value
"value" */

/*
== operator in javascript is called the equals operator. It is used to compare
equals between two values, ignoring their types(number, string, boolean, etc.),
it is used as: */
   (5 == "5") // true
/* ^^^^^^^^^^
here, as you can see, it is asking that 5 is equal to "5", ignoring the type, it
returns true as their value is 5 (Note that "5" is converted to 5 for checking
for == comparator) */

/*
=== operator in javascript is called the strict equals operator. It is used to
compare euals between two values, considering their types(number, string,
boolean, stc.), it is used as: */
   (5 === "5") // false
/* ^^^^^^^^^^^
here, as you can see, it is asing that 5 is equal to "5", considering the type,
it returns false as their values is same, but their type is not (Note that "5"
is not converted into 5 for checking for === comparator) */
Comment

PREVIOUS NEXT
Code Example
Javascript :: drop down listing in angular form 
Javascript :: javascript find string between two characters 
Javascript :: get html tag javascript 
Javascript :: hide a div when user clicks outside of it 
Javascript :: how to modify external json file javascript 
Javascript :: read json from file js 
Javascript :: how do i listen to a keypress in javascript 
Javascript :: Facebook passport Oauth authenticate strategy 
Javascript :: install react native gifted charts 
Javascript :: getting href value in jquery 
Javascript :: check device in flutter 
Javascript :: javascript insert before 
Javascript :: get screen resolution jquery 
Javascript :: nestjs change httpcode inside function 
Javascript :: count no of punctuation in string in js 
Javascript :: vuejs input text 
Javascript :: add image in react native 
Javascript :: get css custom property javascript 
Javascript :: readfilesync return buffer 
Javascript :: Array.include is not a function javascript error help 
Javascript :: convert string to date using moment 
Javascript :: get looping in jquery 
Javascript :: javascript async fetch file html 
Javascript :: how to compare strings in javascript ignoring case sensitive 
Javascript :: Install react router in react app 
Javascript :: javascript change hidden input value 
Javascript :: get input type js 
Javascript :: loop in react depending on number 
Javascript :: mocha should throw error 
Javascript :: ERESOLVE unable to resolve dependency tree Found: react@17.0.2 Could not resolve dependency: react native paper 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =