Errors Flashcards

0
Q

Errors:

What is the value of “d” in this statement?

var d = 7
[1, 2, 3].forEach(function ()... )
A

undefined

If a semicolon is not included at the end of a line it will be combined with the subsequent line if the subsequent line begins with (, [, +, - or /

After the statement is parsed it will be

var d = 7[1, 2, 3].forEach(function ()… )

Beware!

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

Errors:

To combine “strict” and “non-strict” file safely, you can wrap the code in what type of functions?

A

Immediately invoked function expressions (IIFE)

(function( ) {
   /* code */
}) ( );
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Errors:

When joining multiple JavaScript files how can you defend against the accidental concatenation of functions?

A

By prefixing the file with a semicolon.

;function () {….}

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

Errors:

What tools help diagnose possible coding error and bad practices that can lead to faulty code?

A

Lint tools

It is a good practice to use a program like lint or hint to check for errors that might be hidden in your code.

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

Errors:

If the JavaScript engine is unable to look up the value of a variable (typically the right hand side of an equation) what error will it throw?

A

ReferenceError

In strict mode this will also happen for variables on the left hand side of the equation because strict mode will not automatically generate missing variable declaration in the global space.

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

Errors:

If a variable is found but you try to do something illegal with it (like reference a property on undefined) what error is thrown?

A

TypeError

TypeError implies the scope was found while ReferenceError implies the scope was not found.

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

Errors:

Will the code

var CapVar = 5;
capVar += 8;

throw an error?

A

Only in strict mode.

If you are not in strict mode misspelled variables will be declared by JavaScript as a new global variable an the execution will continue.

In strict mode using undeclared variables will throw an error.

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