0
0
Javascriptprogramming~20 mins

Unary operators in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Unary Operator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code using unary plus?
Consider the following JavaScript code. What will be printed to the console?
Javascript
let a = '5';
let b = +a;
console.log(typeof b, b);
Aundefined 5
Bstring 5
Cnumber 5
Dobject 5
Attempts:
2 left
💡 Hint
Unary plus converts strings to numbers.
Predict Output
intermediate
2:00remaining
What is the output of this code using unary negation?
Look at this code snippet. What will it print?
Javascript
let x = 10;
console.log(-x);
A-10
B10
CNaN
Dundefined
Attempts:
2 left
💡 Hint
Unary negation changes the sign of a number.
Predict Output
advanced
2:00remaining
What is the output of this code using prefix and postfix increment?
What will this code print to the console?
Javascript
let i = 3;
console.log(i++);
console.log(++i);
A
4
5
B
4
4
C
3
4
D
3
5
Attempts:
2 left
💡 Hint
Postfix returns the value then increments; prefix increments then returns.
Predict Output
advanced
2:00remaining
What is the output of this code using the typeof unary operator?
What will this code print?
Javascript
let val = null;
console.log(typeof val);
Anull
Bobject
Cundefined
Dboolean
Attempts:
2 left
💡 Hint
typeof null is a known JavaScript quirk.
Predict Output
expert
2:00remaining
What is the output of this code combining unary plus and logical NOT?
What will this code print to the console?
Javascript
let a = '0';
console.log(+!a);
A0
B1
CNaN
Dfalse
Attempts:
2 left
💡 Hint
Logical NOT converts to boolean then negates; unary plus converts boolean to number.