Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 2 /// 2 is 2 in Javascript?

Tags:

javascript

Does anyone know why 2 /// 2 is 2 in Javascript?

What is this behavior called? Is it documented somewhere? Thanks.

like image 556
trivektor Avatar asked Dec 30 '11 00:12

trivektor


People also ask

What is the result of 2 2 in JavaScript?

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 .

What does $() mean in JavaScript?

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 is the output of 2 5 3 in JavaScript?

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.

What would be the result of 1 2 3 in JavaScript?

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.


2 Answers

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".

like image 155
Kenaniah Avatar answered Nov 04 '22 23:11

Kenaniah


// introduces a single line comment in JavaScript

like image 28
Aaron J Lang Avatar answered Nov 05 '22 00:11

Aaron J Lang