JS Basics Flashcards

1
Q

// What will the below code print out?

    "use strict";
    var a = 1;
    var b = {};
    function foo(x, y) {
      x = 2;
    y.moo = 3;
    }
foo(a, b);
console.log("a = " + a + "; b = " + JSON.stringify(b));
A

“a” is passed by value so updates to “a” in function foo will NOT be visible outside of the function foo and “b” being an object is passed by reference, so changes to properties of “b” in the function foo WILL be visible outside of the function foo.

a =1; b = {‘moo’:3}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
// What will the below code print out?
    var asimsVar = 3;
    asimVar = 1;
    console.log(asimVar)
A

What is “use strict” and what does it do?

1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
// What will the below code print out?
    "use strict";
    var asimsVar = 3;
    asimVar = 1;
    console.log(asimVar);
A

What is “use strict” and what does it do?

It will throw an error

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

JavaScript Committee

A

TC39 on Github

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

How to get new features to work in old browswers

A

link to polyfill

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

What is strict mode?

A

Silent errors become

“use strict”; /// string

Strict mode eliminates some JavaScript silent errors by changing them to throw errors.

Strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.

It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object)

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

Does JavaScript pass parameters by value or by reference?

A

privative types by value (copy)

objects by reference (pointer)

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

spread operator …

A
add one array to another one (three dots)
...
var ar2 = [1,2,3, ar1]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

rest operator

A
function login(...options) {
// now have access to the parameter list like an array
}

(three dots)

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