Ready. Start with one instruction.
Loading the learning workspace…
FROM YOUR FIRST INSTRUCTION TO A WORKING APPLICATION
Learn JavaScript from scratch through small working examples, visual experiments and complete projects. No account or AI key required.
Predict → Experiment → Build → Test → Explain
Ready. Start with one instruction.
Loading the learning workspace…
typeof reports a value’s type, while conversion functions deliberately create another representation. Number("12") creates a number; String(12) creates text. Boolean("") is false but Boolean("false") is true because that string is nonempty. This example converts numeric text before addition. Without the conversion, plus would concatenate. Converting invalid numeric text produces NaN, which requires its own validation before a production calculation.
const text = "12";
const number = Number(text);
console.log(number + 1);
console.log(typeof number);13 number
Explicit conversion makes plus perform numeric addition instead of string concatenation.
const text = "12";Declare text with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
const number = Number(text);Declare number with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
console.log(number + 1);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log(typeof number);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
const text = "0";
const number = Number(text);
console.log(number + 1);
console.log(typeof number);1 number
Explicit conversion makes plus perform numeric addition instead of string concatenation.
const text = "0";This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const number = Number(text);Declare number with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
console.log(number + 1);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log(typeof number);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
const text = "5";
const number = Number(text);
console.log(number + 1);
console.log(typeof number);6 number
Explicit conversion makes plus perform numeric addition instead of string concatenation.
const text = "5";This statement belongs to the operation described above. Compare its names, arguments and current state before advancing.
const number = Number(text);Declare number with const. The binding cannot be reassigned. The expression after = supplies its initial value; = is assignment, not an equality comparison.
console.log(number + 1);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
console.log(typeof number);Evaluate the argument and display its value at this point. Quoted text is literal; an unquoted identifier reads its current binding.
Repair the intentionally changed operation so the example produces the exact expected result. Then try the extension without copying the answer.
const text = "12"; const number = text; console.log(number + 1); console.log(typeof number);
const text = "12"; const number = Number(text); console.log(number + 1); console.log(typeof number);
A successful conversion operation still needs validation if input may be blank or invalid.
Which operation changed the result, why did it work, and what would you test next?
Use a different value that could expose a boundary or mistake. Predict the result first, run it, and explain how the concept would help in a small real application.
Related: Previous lesson Next lesson
100 lessons across 20 modules, covering variables, operators, strings, conditions, loops, functions, scope, arrays, objects, DOM, events, state, testing, asynchronous JavaScript and application development.