- Error shown:
- Why it happens:
- MDN link (optional):
- Error shown:
SyntaxError: Unexpected identifier 'is'on line 1. - Why it happens: The file begins with plain English text that is not inside a comment or a quoted string. Node tries to interpret it as JavaScript code, but
This is ...is not valid JS syntax, so parsing fails. - MDN link (optional): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_token
- Error shown:
- Why it happens:
- MDN link (optional):
- Error shown:
TypeError: Assignment to constant variable.on line 4. - Why it happens: The variable
agewas declared withconst, which prevents reassignment. The statementage = age + 1attempts to update the value, causing the error. - MDN link (optional): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const
- Error shown:
- Why it happens:
- MDN link (optional):
- Error shown:
ReferenceError: Cannot access 'cityOfBirth' before initialization. - Why it happens: The variable
cityOfBirthis declared later in the file usingletorconst, but it is used before that declaration. JavaScript does not allow access tolet/constvariables before initialization (temporal dead zone). - MDN link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_access_lexical_declaration_before_init
- Error shown:
- Why it happens:
- MDN link (optional):
- Error shown:
TypeError: cardNumber.slice is not a function - Why it happens: The variable
cardNumberis a number, and numbers do not have theslice()method. Theslice()method is only available on strings and arrays. - Concept: Methods depend on data types in JavaScript.
- MDN link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
- Error shown:
- Why it happens:
- MDN link (optional):
- Error shown:
SyntaxError: Invalid or unexpected token - Why it happens: The variable name
12HourClockTimestarts with a number. JavaScript identifiers cannot begin with a digit, so the parser throws a syntax error. - Concept: Variable naming rules (identifiers must start with a letter,
_, or$) - MDN link: https://developer.mozilla.org/en-US/docs/Glossary/Identifier