+ 43
for those who are still confused in =,==,=== operaters
=(equal) is used for assigning a value to variable, == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if two values are not the same type === will simply return false. It's this case where === will be faster, and may return a different result than ==. In all other cases performance will be the same. Example: 20 == '20' , will return TRUE 20 === '20' , will return FALSE
19 Answers
+ 36
= for assigning a value to a variable
like var age = 20;
== for comparing two variables whether they are of equal type
=== for comparing two variables whether they are strictly equal
sample code:
var age1= 20; //age1 is just a variable not object
var age2 = new number(20); /* age2 is an object here as we used number constructor function using the keyword new */
alert(age1 == age2); // true
alert(age1 === age2); //false
hope this helps you
+ 15
example for ==
var a = "42"; // string
var b = 42; // number
if(a == b) // true
in case of == the comparison is made between two values after the necessary conversion of values of either side from one data type to another. like in the above example ist a is converted into NUMBER from STRING data type and then the comparison occurs and result is true.
but if we have used ===. operator then the result would have been false
because this operator won't let convert the values of either side their data type.
if(a===b) // false
+ 8
== used to compare values, === used to compare both value and datatype
+ 4
Honestly, I'd still be confused after reading this.
+ 4
= is use to denote values like x =5 , now x will have value 5
+ 2
== is usually use to compare value on certain conditions like in IF and FOR loop ...
+ 2
What is java
+ 2
I understood the movie inception
but ,
not this
+ 1
@Codde Ded because age2 is an object whereas age1 is a number
+ 1
`=` Assign value.
`==` Check if the same value.
`===` Check if the same value and data type.
0
= for assigning a value to a variable
like var age = 20;
== for comparing two variables whether they are of equal type
=== for comparing two variables whether they are strictly equal
sample code:
var age1= 20; //age1 is just a variable not object
var age2 = new number(20); /* age2 is an object here as we used number constructor function using the keyword new */
alert(age1 == age2); // true
alert(age1 === age2); //false
0
Define please the terms object and type?
0
me
- 1
@Kandula Samantha, but why is this so?
I would assume age1 and age2 are of the same value types: integers. why would '===' then evaluate to 'false'?
what is the javascript engine comparing here: values against values, or values against value types?
- 1
still confused
- 1
like if u r studying in 2017
- 1
8=="8" ,but 8==="8" no
- 1
good
- 2
me too