I want to know why after running the third line of code the result of a
is 5?
a = 10;
b = 5;
a =+ b;
The strict equality operator ( === ) checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality operator always considers operands of different types to be different.
means that two variables are being checked for both their value and their value type ( 8!== 8 would return false while 8!== "8" returns true). != only checks the variable's value ( 8!=
{} is shorthand for creating an empty object. You can consider this as the base for other object types. Object provides the last link in the prototype chain that can be used by all other objects, such as an Array . [] is shorthand for creating an empty array.
KEY DIFFERENCES: = is called as assignment operator, == is called as comparison operator whereas It is also called as comparison operator. = does not return true or false, == Return true only if the two operands are equal while === returns true only if both values and data types are the same for the two variables.
Awkward formatting:
a =+ b;
is equivalent to:
a = +b;
And +b
is just a fancy way of casting b
to number, like here:
var str = "123";
var num = +str;
You probably wanted:
a += b;
being equivalent to:
a = a + b;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With