+ 5
What is difference between =&== ?
..
4 Answers
+ 12
"=" is used to assign values. Ex:
int x = 5 //x now is 5
"==" is used to compare two expressions. It's is used in conditional statements.Ex:
If(x == 10) //This compare if x equal to 10
+ 5
Well, the "=" is an assignment operator whereas the "==" is used for comparisons and it returns a Boolean value instead of assigning the value on the right and side of it to the variable on the left. For example:
int a=10; //This means I am assigning the a primitive variable named "a" with a value of 10.
if(a==10){ //This compares whether the value of a is equal to 10 or not and returns a Boolean value
System.out.println("true");
}
Hope this helps.
+ 4
example
var x = 7
this assigns the value 7 to the variable x.so now tue value of x is 7.
however ==,
is normally used to test for equality so,
== is (equal to)/(normally used in if statements to test if two values are same.)
= is(used to assign a value to something)