In JavaScript, you have the usual arithmetics operators:
The /
operator yields a floating-point result.
The %
operator works with both integer and non-integer numbers.
There is *
operator (similar to Python) that raises to a power.
If an operand is NaN
, so is the result
Similar to Java, C++ and many other programming languages, you have combined assignment operator:
Similar to Java, C++ and many other programming languages, you can have increment and decrement operators:
Type Coercion is another term for type conversion. The JavaScript community more commonly uses the former.
What do you think is the output?
What do you think is the output?
+
concatenates strings: the non-string argument is converted to string.Don’t mix types!
JavaScript does not say no when you mix up types in expressions. No matter how complex the expression is and what types it involves, JavaScript will evaluate it. The outcome will be surprising and unexpected in many cases. So, never mix types!
I recommend reading freeCodeCamp’s article: JavaScript type coercion explained