+ 4

= vs ==

What's the difference? if(a=b) vs if(a==b)

19th Feb 2018, 6:45 AM
Walker Haywood
Walker Haywood - avatar
7 Answers
19th Feb 2018, 6:55 AM
Jaydeep Khatri
Jaydeep Khatri - avatar
+ 5
(a=b) mean the value of a is b which is defined by = example var b=10; var c=20; var a=b; document.write(a+c) output,*=30 and (a==)it is used to compare if the value of a is equal to value of b
19th Feb 2018, 6:50 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
= assigns value == compares value
19th Feb 2018, 3:01 PM
DeleteThisAccount
+ 1
@Shudarshan Rai, @Immortal, could you elaborate on the assignment operator? (=)
19th Feb 2018, 6:52 AM
Walker Haywood
Walker Haywood - avatar
+ 1
@Immortal Ahh got you, okay so that's why we setup a second = to clarify that it's just to check the equality.
19th Feb 2018, 6:55 AM
Walker Haywood
Walker Haywood - avatar
+ 1
= is assignment operator For example, int a=5; i.e., the value in right hand side is assigned to the variable in left hand side. 5 is assigned to a. == is relational operator and we can say that it is a binary operator because we check for the equality of two variables. For example, int a=5,b=4; if(a==b){} In the above example the if statement checks whether the value in variable a is equal to the value in variable b. When coming to your question the statement if(a=b) throws an error because if statement takes a relational expression only..... Syntax :if(relational expression) I think you know about relational expression...
19th Feb 2018, 1:38 PM
Nashat
Nashat - avatar
+ 1
== :V
19th Feb 2018, 6:06 PM
tryin' to do smth
tryin' to do smth - avatar