Errors and Exceptions #30 Flashcards

1
Q

What are the 7 error objects in JS ?

A
  1. Error
  2. EvalError
  3. RangeError
  4. ReferenceError
  5. SyntaxError
  6. TypeError
  7. URIError
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What properties does Error contain?

A
  1. Message - returns the error description as a human readable message explaining what error occurred.
  2. Name- the type of error that occurred (TypeError or SyntaxError etc)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does RangeError mean?

A

Fires when a numeric value is out of range. For example:
[ ].length = -1 //RangeError: Invalid array length
or
[ ].length = 4294967295 //4294967295
[ ].length = 4294967296 //RangeError: Invalid array length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does ReferrenceError mean?

A

A ReferenceError indicates that an invalid reference value has been detected: a JavaScript program is trying to read a variable that does not exist. Example:

dog //ReferenceError: dog is not defined
dog = 2 //ReferenceError: dog is not defined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does SyntaxError indicate?

A

Self explanatory, however see examples below:

A function statement without name:

function() {
  return 'Hi!'
}  //SyntaxError: function statement requires a name

Missing comma after an object property definition:

const dog = {
  name: 'Roger'
  age: 5
}  //SyntaxError: missing } after property list
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does TypeError indicate?

A

A TypeError happens when a value has a type that’s different than the one expected.

The simplest example is trying to invoke a number:

1( ) //TypeError: 1 is not a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What function does Finally perform?

A

To complete the try/catch statement JavaScript has another statement called finally, which contains code that is executed regardless of the program flow, if the exception was handled or not, if there was an exception or if there wasn’t:

try {
  //lines of code
} catch (e) {

} finally {

}
You can use finally without a catch block, to serve as a way to clean up any resource you might have opened in the try block, like files or network requests:

try {
  //lines of code
} finally {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly