Does anyone know why 2 /// 2
is 2
in Javascript?
What is this behavior called? Is it documented somewhere? Thanks.
So the first "2" and second "2" makes "22". But when performing subtraction ( - ) on strings, coercion happens. So the resulted "22" coerced to number 22 and final "2" coerced to number 2 . Finally subtracts 2 from 22 to result 20 .
Usually when you encounter $() , that means the developer is using a javascript library, such as jQuery. The $ symbol is the namespace for those libraries. All the functions they define begin with $. , such as $. get() .
What would be the result of 2+5+”3″? Since 2 and 5 are integers, they will be added numerically. And since 3 is a string, its concatenation will be done. So the result would be 73.
1+2+ “3” your result would be “33” as “+” on two numbers would result in an addition operation and then that result would be concatenated to your string. You can try this in your browser console by clicking on the F12 key on your keyboard or checking out the options.
It's called commenting. Anything that starts with //
is a single-line comment.
Your code is essentially 2
as the rest of the line is a comment of "/ 2
".
//
introduces a single line comment in JavaScript
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