InterviewHubPRO
Section Overview
Q246

Question 246 of 521

Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

47%
JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)

What is an Unary operator

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
  var x = "100";
  var y = +x;
  console.log(typeof x, typeof y); // string, number

  var a = "Hello";
  var b = +a;
  console.log(typeof a, typeof b, b); // string, number, NaN