Basics Flashcards

1
Q

What’s exponent operator?

A

**

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

What’s the difference between == and ===?

A

Strict equality (no attempt at type conversion)

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

What are the three methods for declaring strings?

A

’ ‘, “ “, ` `

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

How do you add quotation marks inside a string?

A

with the \ (escape) character

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

What are commonly used escape characters in strings?

A
Code	Output
\'	single quote
\"	double quote
\\	backslash
\n	newline
\r	carriage return
\t	tab
\b	word boundary
\f	form feed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does it mean to say string values are immutable?

A

They cannot be altered once created, only assigned a new string.

Not allowed:
var myStr = "Bob";
myStr[0] = "J";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the scope of variables assigned without the var keyword?

A

global

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

What happens when a local and global variable have the same name?

A

the local variable takes precedence

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

What’s the syntax for a switch statement?

A
switch(lowercaseLetter) {
case "a":
console.log("A");
break;
case "b":
console.log("B");
break;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How are case values in a switch statement evaluated?

A

with strict equality

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

How do you execute a case in a switch statement if no matching values are found

A

with default

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

What does break do in switch statements?

A

tell javascript to stop executing statements

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

What’s the syntax for a switch statement that has multiple inputs with the same output?

A
switch(val) {
case 1:
case 2:
case 3:
result = "1, 2, or 3";
break;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the two ways to access object properties?

A

There are two ways to access the properties of an object: dot notation (.) and bracket notation ([])

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

What’s the syntax for declaring an object?

A
var myObj = {
prop1: "val1",
prop2: "val2"
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When would you use dot notation to access an objects properties?

A

When you know the key name and it has no spaces.

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

What’s the syntax for accessing an object’s values when the key name has spaces?

A

myObj[“Space Name”]; // Kirk
myObj[‘More Space’]; // Spock
myObj[“NoSpace”]; // USS Enterprise
Note that property names with spaces in them must be in quotes (single or double).

18
Q

How do you access an object’s values when the key name is a variable?

A

With bracket notation and no quotes around the variable.

19
Q

What’s the syntax for deleting an object’s property?

A

delete ourDog.bark;

20
Q

What function checks if an object has a property?

A

.hasOwnProperty(propname)

21
Q

What’s the syntax for a while loop?

A

while(i < 5) {
ourArray.push(i);
i++;
}

22
Q

What’s the difference between a while and do..while loop?

A

A do…while loop executes the loop body at least once

23
Q

What’s the syntax for a do…while loop?

A

do {
ourArray.push(i);
i++;
} while (i < 5);

24
Q

What does Math.random() do?

A

generates a random decimal number between 0 (inclusive) and not quite up to 1 (exclusive). Thus Math.random() can return a 0 but never quite return a 1

25
Q

How do you generate random whole numbers?

A

Math.floor(Math.random() * 20);

26
Q

How do you generate random numbers between a maximum and minimum value?

A

Math.floor(Math.random() * (max - min + 1)) + min

27
Q

How do you convert a string to an integer?

A

var a = parseInt(“007”);

28
Q

How do you convert a string to a number of a different base?

A
var a = parseInt("11", 2);
The radix variable says that "11" is in the binary system, or base 2. This example converts the string "11" to an integer 3.
29
Q

What’s the syntax for a one line if-else expression?

A

condition ? expression-if-true : expression-if-false;

30
Q

What’s the syntax for a multi-line ternary operator?

A
function findGreaterOrEqual(a, b) {
return (a === b) ? "a and b are equal"
\: (a > b) ? "a is greater"
\: "b is greater";
}
31
Q

What’s the ES6 syntax for declaring functions?

A
let name = (num1, num2) => {
body
}
32
Q

What does a function without the return keyword return?

A

undefined

33
Q

What’s the ES5 syntax for a regular function?

A
function name(num1, num2) {
body
}
34
Q

What’s the ES5 syntax for an anonymous function?

A
let name = function(num1, num2) {
body
}
35
Q

What’s the syntax for looping through an object?

A

for (let key in obj) {
body
}

36
Q

How do you execute a function on each element of an array?

A

forEach()

37
Q

How do you combine all the elements of an array into a single string?

A

join()

38
Q

How do you find the index of a single element in an array?

A

indexOf()

39
Q

How do you extract a sequential part of an array?

A

arr.slice([start[, end]])

the resulting array will include the start, but not the end

40
Q

How do you change the contents of an array by removing or replacing existing elements?

A

.splice

let arrDeletedItems = arr.splice(start[, deleteCount[, item1[, item2[, …]]]])

41
Q

What does the splice function return?

A

the array of deleted elements

42
Q

How do execute a function on an array and return a new array?

A

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

const map1 = array1.map(x => x * 2);