Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

In JavaScript what is the difference between == and =?

user-image
Question ajoutée par Samar Saleh , Community Manager , Bayt.com
Date de publication: 2014/01/20
Marian Mesbah
par Marian Mesbah , Software Developer , Amana Financial Services Ltd

= for assigning value to variable

== for comparing to values in if conditions 

medhatmahmoud mahmoud
par medhatmahmoud mahmoud , Web Designer , Connect Computer Service Co

=    assign a value to variable

== equal   (equal for value)

===  identical  (equal for value and data type)

 

Mohammad Arif
par Mohammad Arif , Principal Engineer UI , NatWest Group

The = (Assignment) operator is used to assign values.

The == (Equality) operator will compare for equality after doing any necessary type conversions

The === (Identity) operator behaves identically to the equality (==) operator except no type conversion is done, and the types must be the same to be considered equal.

 

 

Okeowo Remi
par Okeowo Remi , Software Engineer , Interswitch Group

The "=" is an Assignment operator, it assign the value of the right hand operand to left hand operand

e.g

var Name="Samer Saleh";

var What_is_my_name=Name;

What_is_my_Name now holds the value of the Name, depending on the type of value, sometimes it might contain other than a value, sometimes it can also act as a reference to another variable;

e.g

var x=[1,2,4] var y;

y=x;

x.push(5);

 

On the other hand "==" is a logical operation it compares two operands

e.g var a=2, var b=3; (a == b) will yield to false, however "==" does a type conversion before comparing the value, this can lead to undesired effect, "===" is prefered in the JavaScript community because it operates in operand of the same type and is faster than the previous. 

 

Abdulhakeem Al-Dbeb
par Abdulhakeem Al-Dbeb , Distance Learning Technology Specialist , Indiana State University

' == ' is a reference comparison and ' = ' to evaluate the comparison of values in the objects.

Syed Hussain Moosa
par Syed Hussain Moosa , Senior Software Engineer , Emirates Airlines

"=" is used to assign value to variable where as "==" used to compare the values.

Ajay Kollipara
par Ajay Kollipara , Associate Software Engineer , Inspiredge It Solutions

= is an "Assignment Operator".

example var a = 53;

 

== is  used for comparison. It is a comparison Operator

example if a ==b

Mousa Alyaseen
par Mousa Alyaseen , warehouse and logistics coordinator , BASF - Master Builders Solution

the operarion (=) used to set values or variables to variables.

example a =3 , a = text1.value.

the operation (==)  used to compare2 variable or values. 

example a == b, a==2 , >, <, >=, =<, ....etc

irfan shaikh
par irfan shaikh , Consultant : Senior Web Designer/Front end Developer , Client : ● Impact Proximity, Dubai ● Cube Solution, Dubai ● WAC, Sharjha ● KIOEC, Kuwait ● IRIS Ltd.

As all answer above mentiond "=" is assignment operator that assign the value of any variable, reference etc.

 

 "==" is equality operator that check the value of right hand to left hand the result will be the boolean value.

Ahmed Hisham
par Ahmed Hisham , Marketing Consultant - Web Developer , CPI Group

"=" is an assign operator that assigns right operand to left operand.

"==" is a comparison operator that check if both right and left operands are equal in value or not.

"===" is a comparison operator that check if both right and left operands are equal in both value and data type or not.

Mahmoud Elmahdi
par Mahmoud Elmahdi , UX/UI Designer, Web Developer , ikantam.com

Here's you will find everything about Comparison Operators in details.

 

Hope this helps.

Mahmoud, Cheers

More Questions Like This