Exercises 1

1.Write a function that generates a RangeError.

Answer:

(10).toPrecision(-1)
/*
VM596:1 Uncaught RangeError: toPrecision() argument must be between 1 and 21
    at Number.toPrecision (<anonymous>)
    at <anonymous>:1:6
(anonymous) @ VM596:1 */ 

2.Write a function that generates a ReferenceError.

Answer:

letsDoThis();
/*
VM620:1 Uncaught ReferenceError: letsDoThis is not defined
    at <anonymous>:1:1 */

3.Write a function that generates a URIError.

Answer:

decodeURIComponent('%');
/*
VM792:1 Uncaught URIError: URI malformed
    at decodeURIComponent (<anonymous>)
    at <anonymous>:1:2 
    */ 

Exercises 2

1.Generate a ReferenceError, but catch it before it reaches the browser console. You do not need to handle the error in any way, just prevent it from being displayed in the browser’s console.

Answer:

try {
    decodeURI('%AF');
} catch (error) {
    
}

Exercises 3

1.Create a function that returns the square of the number that is passed to it. Throw the string argument is not a number if a non-numerical argument is passed to the function.

Answer:

See the Pen argument is not a number ex. by oscar (@nopity) on CodePen.