JS Coding Questions Logo
JS Coding Questions
#242💼 Interview💻 Code

What is an Unary operator

Advertisement

728x90

The unary(+) operator is used to convert a variable to a number.If the variable cannot be converted, it will still become a number but with the value NaN. Let's see this behavior in an action.

javascript
1var x = "100";
2
3var y = +x;
4
5console.log(typeof x, typeof y); // string, number
6
7var a = "Hello";
8
9var b = +a;
10
11console.log(typeof a, typeof b, b); // string, number, NaN

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 71

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
242of476