What is a `ReferenceError` in JavaScript?
A
An error caused by using a variable that hasn't been declared B
An error when the browser crashes C
An error caused by incorrect math D
An error when accessing arrays
Analysis & Theory
A `ReferenceError` occurs when you use a variable that is not defined.
Which of these will cause a `TypeError`?
A
Calling a non-function value as a function B
Misspelling a variable name C
Missing a semicolon D
Using an `if` without `else`
Analysis & Theory
A `TypeError` occurs when a value is not the expected type, e.g., calling `5()`.
What does a `SyntaxError` indicate?
A
Logic failure B
Invalid code structure C
Browser crash D
Null pointer
Analysis & Theory
A `SyntaxError` means the code cannot be parsed, like missing brackets or invalid characters.
What will this code throw?
```js
let x = ;
```
A
ReferenceError B
SyntaxError C
TypeError D
RangeError
Analysis & Theory
Missing a value after `=` causes a `SyntaxError`.
Which error is thrown when a number is outside the allowed range?
A
ReferenceError B
RangeError C
SyntaxError D
TypeError
Analysis & Theory
A `RangeError` occurs when a number is outside a valid range, like array length too big.
How can you catch an error in JavaScript?
A
try {} catch {} B
if (error) {} C
catch(error) {} D
catch try {}
Analysis & Theory
Use `try...catch` to handle errors safely in code.
What happens if an error occurs inside `try` block?
A
The browser crashes B
The code continues normally C
The error is thrown and the `catch` block runs D
Nothing happens
Analysis & Theory
When an error is thrown in `try`, control moves to the `catch` block.
What is the purpose of `finally` in error handling?
A
To handle undefined errors B
To run code only if there's no error C
To always run code after try/catch D
To log syntax errors
Analysis & Theory
`finally` runs regardless of whether an error occurred or not.
Which of these will cause a `ReferenceError`?
```js
console.log(myVar);
```
A
myVar is declared B
myVar is assigned a value C
myVar is not declared D
myVar is inside an object
Analysis & Theory
Using a variable before it's declared causes a `ReferenceError`.
How can you create a custom error in JavaScript?
A
new Error('message') B
Error.create('message') C
throwError('message') D
logError('message')
Analysis & Theory
Use `new Error('message')` and throw it using `throw` keyword.