Challenge - 5 Problems
JavaScript Dynamic Typing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this code with dynamic typing?
Consider the following JavaScript code. What will be printed to the console?
Javascript
let x = '5'; x = x + 3; console.log(x);
Attempts:
2 left
💡 Hint
Remember that + operator with a string converts the other operand to string.
✗ Incorrect
In JavaScript, when you add a number to a string, the number is converted to a string and concatenated. So '5' + 3 becomes '53'.
❓ Predict Output
intermediate2:00remaining
What is the type of variable after reassignment?
What will be the output of the following code?
Javascript
let data = 10; data = 'hello'; console.log(typeof data);
Attempts:
2 left
💡 Hint
Variables in JavaScript can hold any type and can be reassigned.
✗ Incorrect
Initially data is a number, but after reassignment it holds a string, so typeof returns 'string'.
❓ Predict Output
advanced2:00remaining
What is the output of this dynamic type coercion?
What will this code print to the console?
Javascript
console.log('5' - 3);
Attempts:
2 left
💡 Hint
The - operator converts strings to numbers if possible.
✗ Incorrect
The - operator triggers numeric conversion, so '5' becomes 5 and 5 - 3 equals 2.
❓ Predict Output
advanced2:00remaining
What error does this code raise due to dynamic typing?
What happens when this code runs?
Javascript
let a = null; console.log(a.toUpperCase());
Attempts:
2 left
💡 Hint
null has no methods and cannot be used like a string.
✗ Incorrect
Calling a method on null causes a TypeError because null is not an object.
🧠 Conceptual
expert3:00remaining
Which option shows the correct dynamic type change and output?
Which code snippet will output the number 10 after dynamic typing changes?
Attempts:
2 left
💡 Hint
The unary + converts string to number before addition.
✗ Incorrect
Option B converts '5' to number 5 using unary +, then adds 5 to get 10. Others produce strings or 0.