Week-4 Flashcards

1
Q

Javascript is always executed sequentially

A

True

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

HTML:

Is this HTML valid?

A

No, it’s missing a closing ‘script’ tag. It must always be there.

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

Identify valid Javascript code snippet(s)

A
a) var x = "Hello world!";
Regular variable declaration.
b) var x = function () {
  console.log("Hello World");
  return;
};
It's valid. The 'return' statement here doesn't do much as the function will return anyway without it.
c) var x = function () {
  console.log("Hello World");
  return;
};
x();
Valid. The last line simply executes/invokes the function.
d) var x = function () {
  console.log("Hello World");
  return;
};
x = "hello, I am a new value!";
Valid. Javascript has dynamic typing, so 'x' can be a function and then can change to be a regular string.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

An object in Javascript is simply a collection of name/value pairs.

A

True

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

In Javascript, a primitive type can store only 1 name/value pair at a time.

A

False as Primitive values are NOT name/value pairs. They are single values.

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

Strict equality operator (===) differs from regular equality operator (==) in that it checks if both values on its right and left are of the same type first. If they are not, it doesn’t try to coerce them to be the same value and just returns false.

A

True

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

JS:
var x = 10;
if ( (null) || (console.log(“Hello”)) || x > 5 ) {
console.log(“Hello”);
}
How many times will the word ‘Hello’ be printed to the console?

A

2
Since we are using an OR operator, the ‘if’ statement will stop evaluating conditions after it encounters the very first clause that evaluates to true.
null is false, so we continue
console.log(“Hello”), prints “Hello” to the console and returns nothing, so it’s ‘undefined’ and ‘undefined’ is false, so we continue
x > 5 is true, so we execute the body of the ‘if’ statement and print another “Hello”.
So, the answer is that “Hello” will be printed to the console 2 times.

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

Defining a variable as an Object Literal accomplishes pretty much the same thing as defining a variable equal to ‘new Object()’. However, it’s faster and easier to type up an object literal.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
What is the output for the following Javascript code:
function makeMultiplier(multiplier) {
  var myFunFunc = function (x) {
    return multiplier * x;
  };

return myFunFunc;
}

var operation = makeMultiplier(10);
console.log(operation(10));
A

100

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

Javascript doesn’t allow anything to be passed by reference

A

False

Objects are passed by reference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Output of:
var x = 5;
var y = x;
x = 10;
console.log(y);
A

5

as Primitives are copied by value, so ‘y’ is not connected to ‘x’ in any way.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
Output of JS:
function Dog(name) {
  this.name = name;
}

Dog.prototype.bark = function () {
console.log(this.name + “ likes barking! Bark!”);
}

var max = new Dog("Max", "Buddy");
max.bark();
A

Max likes barking! Bark!

as The second argument is not used in the function but it’s perfectly legal to pass it in.

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

Output of JS:
var counter = 0;
var myArray = [“Yaakov”, 2, {handle: “yaakovchaikin”}];
for (var i = 0; i < myArray.length; i++) {
counter++;
}
console.log(counter);

A

3

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

Immediately Invoked Function Expressions are usually used to place code into its own execution context not to conflict with the global scope.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
Code:
1  (function(window) {
2 
3  var obj = {};
4
5  obj.dreamOn = function () {
6   console.log("I want to see the global scope! Let me out!");
7  };
8
9  window.doer = obj;
10 
11 });
12
13 doer.dreamOn();
What (if anything) is missing from this code in order to get it to output the message of the "dreamOn" method?
A

The attempted IIFE is not being invoked and passed in the window object. It’s missing ‘(window)’ Line 11 right before the semicolon.

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