ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Samar Saleh , Community Manager , Bayt.com
تاريخ النشر: 2014/01/20
Marian Mesbah
من قبل Marian Mesbah , Software Developer , Amana Financial Services Ltd

= for assigning value to variable

== for comparing to values in if conditions 

medhatmahmoud mahmoud
من قبل 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
من قبل 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
من قبل 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
من قبل 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
من قبل Syed Hussain Moosa , Senior Software Engineer , Emirates Airlines

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

Ajay Kollipara
من قبل 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
من قبل Mousa Alyaseen , Senior Logistics Administrator II , Alkhorayef Petroleum Company

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
من قبل 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
من قبل 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
من قبل 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

المزيد من الأسئلة المماثلة