Javascript Interview Questions #javascript #frontend

preview_player
Показать описание
Tricky JS Interview Questions

#webdevelopment #coding #programming #programmers #javascript
Рекомендации по теме
Комментарии
Автор

In JavaScript, when you try to call a method directly on a number literal, like 123.toString(), it throws a syntax error. This is because the dot (.) is interpreted as a decimal point, rather than a method call.
To avoid this, you can wrap the number in parentheses, like (123).toString(), which tells JavaScript to treat the number as an expression and allows you to call the method on it.
Alternatively, you can also use the Number object to call the toString() method, like Number(123).toString().
Here are some examples to illustrate the difference:
123.toString() // SyntaxError: Invalid or unexpected token
(123).toString() // "123"
Number(123).toString() // "123"
This quirk applies to other methods as well, like toFixed() or toPrecision(). So, to be safe, it's a good practice to wrap number literals in parentheses when calling methods on them.

singhkr
Автор

Sir ye 3rd line pe undefined ku aa rha hai

Ajay-ckcm
Автор

I was right about 2nd line will give error

Developer_Himansu
Автор

is hisab data.toString() error q nhi aaya boss, please complete karo video

letsexplore
visit shbcf.ru