Skip to main content
InterviewHubPRO
Section Overview
Q246

Question 246 of 536

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

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

What is an Unary operator

junior LevelMost AskedCode ExampleEvent LoopPrototypes

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