Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT FOUNDATIONS / CHAPTER 01 / Learn / LESSON 06
Sixth class. Forms and notes often give text "50", but math needs the number 50.
Number("50") → 50. Number("99.5") → 99.5. If the string is not a valid number, you get NaN (Not a Number) — an error signal.
After conversion, typeof amount should be "number". Then amount + 10 adds instead of concatenating.
Mini example:
const raw = "12"; console.log(Number(raw));
Common mistake: Number("50 EUR") → NaN because of letters. Start with a clean digit-only string.
Number("50") yields 50. typeof confirms the type.
JS CONSOLE IDLE
›