+ 4
= vs ==
What's the difference? if(a=b) vs if(a==b)
7 odpowiedzi
+ 6
Assignment Operators
https://www.sololearn.com/learn/2282/?ref=app
+ 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
+ 2
= assigns value
== compares value
+ 1
@Shudarshan Rai, @Immortal, could you elaborate on the assignment operator? (=)
+ 1
@Immortal Ahh got you, okay so that's why we setup a second = to clarify that it's just to check the equality.
+ 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...
+ 1
== :V