javascript Flashcards

1
Q

Does a variable have to be declared and assigned at the same time?

A

No, you can give it a name and then later in the code assign it a variable

var a;

(then later)

a = 7

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

what do we put at the end of our code to signify that it is the end?

A

;

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

What is the assignment operator?

A

=

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

what does the assignment operator do?

A

it assigns a value to a variable name

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

what does console.log( ) do?

A

allows you to see things in the console.

console.log(a);

this will return the value of (a) in the console

a = 7

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

can you use console.log ( ) to see what variables were at specific points in your program? how?

A

yes, you can. You can place console.log ( ) both before and after the change of value and it will print out the different values for each assignment

a = 7
console.log(a)

a = ‘happy’

console.log(a)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
7
‘happy’

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

what does a not defined string or name cause?

A

an error

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

what is the value set to a variable name that has not been assigned a value?

A

undefined

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

how can you increment number values by one?

A

variableName++;

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

how can you lower number values by one?

A

variableName–;

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

what are decimal numbers called?

A

floats

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

what is the operator to find the remainder of two numbers?

A

%

10 % 2;
= 0 (no remainder)

11 % 3;
= 2 (remainder)

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

what do we often use the remainder operator for?

A

to figure out if a a number is even or odd. If we can divide a number by 2 and it returns a remainder of 0, then it is even.

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

What shorthand can you use to add a variable name to a number? For instance, a = a + 7.

A

+=

a += 7

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

What shorthand can you use to subtract a variable name to a number? For instance, a = a - 7.

A

-=

a-=7

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

What is it called when you use the shorthand to apply an arithmetic operator to a variable name? (ex: a += 12)

A

Compound assignment

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

What do we need to remember about what happens to the variable name when using Compound Assignment?

A

the new value becomes assigned to the variable name. It doesn’t just compute it to find the answer.

(ex)
a = 2 
a + 2 = 4
console.log(a) 
2

b = 6
b += 2 = 8
console.log(b)
b = 8

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

How do we use Compound Assignment with multiplication?

A

*=

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

How do we use Compound Assignment with division?

A

/=

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

what are three different things that can enclose a string?

A

single quotes ‘ ‘
double quotes “ “
backticks ` `

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

When we are using double quotation marks to enclose a string, how do we use double quotation marks inside of our string without the engine interpreting it as the end of the string?

A

You use the escape character \ before the inside “ - this tells the engine that they are just quotation marks and not the end of the string.

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

what is a literal string?

A

it’s a group of characters that are enclosed in single, double quotes pr backticks. The engine doesn’t interpret anything inside the sting until it receives a matching closing quotation mark.

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

When using single quotation marks to enclose a sting, how do we use single quotation marks inside of our string without the engine interpreting it as the end of the sting?

A

You use the \ escape character, in the same way you would with double quotes.

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

what if you use one type of quotes to enclose a literal string and another type of quotes inside the string?

A

Then there is no problem. You do not need to use an escape character.

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

Can we use backticks to enclose a string with single and double quotes inside them?

A

Yes we can

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

Recommended way to enclose a string?

A

with single quotes if you don’t a specific reason to use double or backticks

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

How do you escape a backslash in a string? And what does it do?

A


when you add a single backslash in a string it doesn’t show up when you render it. Escaping a backslash by using \ makes a single backslash appear.

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

What does the escape character \n inside of a string do?

A

it puts whatever that follows it inside the string on a new line.

(ex)
happy = ‘I want to \n be happy ‘

(result)
‘I want to
be happy’

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

what does the escape character \t inside of a string do?

A

it takes a tab space inside of the string

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

What is concatenating?

A

its adding two strings together end to end

string = “I need to start “ + “doing this regularly”
console.log(string)

“I need to start doing things regularly”

or we can do this

run = ' i want to do'
walk = ' what i want to do '

run + walk = ‘ i want to do what i want to do ‘

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

What should we make sure we do when we are concatenating two or more strings as far as spacing?

A

we should make sure that there is space on the ends of the strings, so when it renders there is a space between them and looks normal and not smashed together.

“i want to “ + “go home” = ‘I want to go home’

‘i want to’ + ‘go home’ = ‘i want togo home’

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

Concatenating with Combined Assignment?

A

Just like you can add variable names to numerical values, to create new values for the variable names.

you can also do that with strings as well.

myStr = ‘ i went home’ += ‘ so i could sleep’

myStr = ‘ I went home so i could sleep’

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

How can we concatenate strings inside of other strings?

A

the same way we add other forms of strings, with the + operator.

myName = 'Rashaan' 
greeting = ' Hey how are you' + myName + ' How have you been?'

console.log(greeting)
“ Hey how are you Rashaan How have you been?”

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

How can we find the length of a string?

A

variableName.length

var name = ' rashaan' 
name.length 

7

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

What does the number return on .length signify?

A

the number of characters in a string

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

what is indexing in a string?

A

its the built in function by the engine that assigns every character in a string a numerical value.

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

What is the first character in a string indexed as? (i.e. What does javascript start counting with?)

A

0.
rashaan
0123456

So the character length will come back as 7
but the actual count of the index will go up to 6 only because counting starts at 0

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

how do use Bracket Notation to find specific index of character in a string?

A

variableName[number}

the corresponding number will find the character that matches it and return it.

name = ‘rashaan’

name[0] r
name[3] h
name [6] n

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

What does immutable mean?

A

it means once something has been set, it is unable to be changed

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

Are the characters in strings mutable or immutable?

A

The characters in strings are immutable, they cannot be changed once they have been set.

(ex)
name = ‘danny’

name[0] = ‘m’

this will not result in ‘manny’ because characters inside of strings cannot be changed once they have been set. This will result in an error

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

Are whole strings immutable when assigned to variable name?

A

No, you can change the value to a variable name as much as you want.

name = ‘rashaan’
console.log(name)

name =’jenan’
console.log(name)

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

How do we use Bracket Notation to find the last character in a string? Especially if you don’t know how many letters there are in a string?

A

variableName [variableName.length -1]

name = ‘rashaan’
name[name.length - 1]

‘n’

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

What is ‘n’ or ‘nth’ number?

A

is it just a placeholder for an unidentified number or number value

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

How to use Bracket Notation to find the ‘nth - last’ character in a string?

A

You use the same syntax as finding the last character in a string, except you change the - 1 to a higher integer.

name = ‘rashaan’
name[name.length - 3]

‘a’

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

What is the value set to a string or a name that has not been declared to a keyword? (var, let, const etc.)

A

not defined

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

when using the additional operator to concatenate multiple parameters representing strings, what should we keep in mind as far as spacing?

A

We have to make sure that not only do we put spacing in between our strings inside of the opening and closing quotes, but we also need to make sure that we are putting spaces in between the parameter names. We do this using empty strings between the parameters.

result = “ The “ + adjective + noun + verb “ home”
console.log(result( ‘funny’, ‘boy’, ‘ran’));

The funnyboyran home

result = “ The “ + adjective + “ “ + noun +” “ + verb “ home”
console.log(result( ‘funny’, ‘boy’, ‘ran’));

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

When using multiple parameters in a function and then setting arguments to those parameters, what do we need to keep in mind when it comes to placement to ensure the proper order takes place in our desired code?

A

The order in which we put the arguments has to match the location of the parameter

function wordBlanks ( param 1 , param 2){
return param 1 + param 2}
console.log(wordBlanks( "dog", 'house')
console.log(wordBlanks( 'house, 'dog')

doghouse
housedog

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

What do arrays always start and end with?

A

a bracket

[ array ]

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

What do arrays always start and end with?

A

brackets

[ array ]

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

what are the elements inside of an array separated with?

A

a comma

[ element1, element2]

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

Can arrays contain elements of different data types inside of them/

A

yes

[ “Austin”, 3.16]

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

Can you use arrays inside of other arrays?

A

yes, arrays are allowed to contain arrays

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

What is a Nested Array?

A

It is an array that is inside of another array

nestedArray = [[“Giants”, 25], [49ers, 16]]

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

Can we use Bracket Notation in an array to index particular elements?

A

yes we can,

ourArray = [50, 60, 70]
ourArray[0]

returns 50

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

What is the difference between indexing a character in a string, and indexing an element in an array, as far as the value that is returned?

A

string indexing only gives the character
array indexing gives us the whole element and not just a specific element character.

string = ‘rashaan’

string[0] = ‘r’

array = [50, 60, 70]

array[0] = 50

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

How do we modify array data with indexes? Are arrays immutable?

A

No, they are not immutable. The way we couldn’t change a character in a string once it has been set, we can do in an array.

niners = [ 33, 43, 55]
niners[2] = 16

niners = [33, 43, 16]

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

What are Multi-Dimensional Arrays?

A

Arrays with multiple arrays inside of them. They are an array of arrays

multi = [[1,2,3],[4,5,6],[7,8,9]]

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

How do we use Bracket Notation to index in Multi-Dimensional Arrays?

A

we use two seperate brackets. The first indexing the whole array, and then the second to specify the specific element

multi = [[1,2,3],[4,5,6],[7,8,9]]

multi[2][1];
8
multi[1][0];
4

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

How do we index a Nested Array inside of a Multi-Dimensional Array?

A

You add more bracket indexing to specify which element you want to greater detail.

var multi = [[1,2,3],[4,5,6],[7,[8,9]]]

multi[2][1][0];
8

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

How do we append a single or single elements to the end of arrays with push( )?

A

you add .push( ) to the name of the array and add what you want to be added to the end of the array inside the parens.

happy = [“john”, ‘dave’, ‘mike’];
happy.push(‘larry’);

happy;
[“john”, “dave”, “mike”, “larry”]

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

How do we append an array or arrays to the end of arrays with push( )?

A

add .push( ) to the name of the array and an array or arrays inside the parens with the included [ ]’s

sad = [‘sad’, ‘happy’, ‘meh’]
sad.push([‘content’,’hyped’])

sad;
[“sad”, “happy”, “meh”, ‘‘content”, “hyped”)]

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

How do we append an array or arrays to the end of arrays with push( )?

A

add .push( ) to the name of the array and add an array or arrays inside the parens with the included [ ]’s

sad = [‘sad’, ‘happy’, ‘meh’]
sad.push([‘content’,’hyped’])

sad;
[“sad”, “happy”, “meh”, ‘‘content”, “hyped”)]

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

What is the pop( ) function used for?

A

the pop function removes the last element from an array

arrayName[“austin”, 3.16]
arrayName.pop( )

arrayName;
[“austin”]

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

How do we remove an element from an array, and simultaneously assign it to a new variable name?

A

use a new variable name plus an assignment operator and the pop function in one line of code

arrayName = [‘austin’, 3.16, ‘says i just whooped your ass’];

var newVariableName = arrayName.pop( );

arrayName;
[“austin”, 3.16]

newVariableName;
“says i just whooped your ass”

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

How do we remove an array from an array using pop? And how do we assign it to a new variable name?

A

you use the same method that you would with a singular element

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

What is the shift( ) function?

A

it works almost exactly like pop( ). But it removes the first element of an array rather than the last element

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

What does the unshift ( ) function do?

A

unshift works exactly like the push function, except instead of adding an element or an array to the end of an array, it adds it to the front of an array

array = [‘dog’, ‘cat’, ‘wolf’];
array.shift( );
“dog”

array.unshift(‘happy’);

array;
(3)[“happy”, “cat”, “wolf”]

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

What are functions? What is their purpose?

A

to create reusable code

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

what does it mean to ‘call’ a function?

A

to call it to action, to run the action inside the curly brackets

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

how do you call a function?

A

use the name of the function followed by parens

nameFunc ( );

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

when you create a function, does it automatically run?

A

no, it will not run until you call it

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

in what way is a function repeatable when it doesn’t have any parameters?

A

It is repeatable but not modifiable, meaning you can run it over and over again without having to retype the code.

function test( ){
    console.log('write this in console')
}

test ( )
test ( )
test ( )

these three function calls of test ( ) would run the function code three separate times

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

in what way is a function repeatable when it has parameters?

A

it is repeatable and modifiable. Not only can you repeat the action that the function preforms, but you can modify the input and information that function renders or works with.

function newFunc(newStatement){
    console.log(newStatement);
}

newFunc(‘Hi my name is’)

newFunc(‘what?’)

newFunc(‘My name is’)

newFunc(‘who?’)

newFunc(‘chika chika Slim Shady’);

result:

Hi my name is
what?
My name is
who?
chika chika Slim Shady.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
74
Q

What is a parameter?

A

a parameter is the place holder in a function that will be modified later when the function is called

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

what is an argument?

A

an argument is the specified data that will replace the placeholder/parameter when the function is called

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

What does ‘scope’ refer to?

A

To the visibility of variables

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

variables that are defined outside of a function block have what type of scope?

A

Global Scope

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

What does Global Scope mean?

A

It means it can be seen anywhere in your JS code.

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

variables that are defined inside of a function using the var keyword has what type of scope?

A

Local scope.

The scope is tied to that function.

function funcName ( ){
    var red = 'blue';
    console.log(red);}

<b> later in code:</b>
red;
VM9788:1 Uncaught ReferenceError: red is not defined

console.log(red);
VM9836:1 Uncaught ReferenceError: red is not defined

<b> when running the function: </b>

funcName( );
blue

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

variables that are defined inside of a function without using a keyword get what type of scope?

A

Global scope.

function globalScope( ){
    red = 'blue';
    console.log(red);
}

<b> The variable ‘red’ has the value of blue, not only when the function is ran, but when it is put anywhere in the code because it is global</b>

globalScope( );
blue

red;
“blue”

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

What is Local/Block Scope?

A

Local/Block Scope is when a variable and its value is tied to a function and parameters that it was defined in

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

Is it possible to have Global and Local/Block variables with the same name?

A

yes you can.

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

when you have a Global and Local/Block variable with the same name, which variable takes precedent when you call a function?

A

The local/block variable takes precedent.

<b> outside of function</b>

var outerWear = ‘Tshirt’;

<b> function </b>

function myOutfit( ) {
    var outerWear = 'sweater';
    return outerWear;
}

<b> Notice that the Local Scope variable only takes precedent when the function is called, and not over the variable name itself in all cases </b>

outerWear;
“Tshirt”

console.log(outerWear);
Tshirt

myOutfit( );
“sweater”

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

What does the return keyword do?

A

it creates a return statement in a function that will return a value when the function is ran.

function math(a){
return a - 5; 
}

console.log(math(10));

5

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

Do we need to add return statements to functions?

A

No we don’t have to

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

If we don’t have a return keyword in our function and don’t specify a value in our function what does it return?

A

undefined

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

How can we assign a define/declare a variable name to the value of a function?

A

variableName = functionName(argument);

<b> This makes the value of the function assigned to the variable ‘num’</b>

function inNum(a){
    return a + 3;
} 
num = inNum(10);
13

num;
13

<b> Notice that this doesn’t affect the future use of the function, the function is just a shell and hasn’t been run or called yet. You can still console log it to get a different value</b>

console.log(inNum(4));
7
undefined

<b> You can change the argument value and assign it to a different value as many times as you want</b>

dude = inNum(1400)
dude
1403

man = inNum(500)
man
503

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

What are the only two Boolean values?

A

True or False

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

What does an If statement do ?

A

it allows you to set one type of code to run if a statement is true and another one if it is false.

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

What is the syntax for an If statement?

A
function functionName {
If ( conditional statement){
code ran if statement is true/false}
)

var a = 22;

function tryIf( ){
    if(a === 22) {
        return ' yeah its true';
    }
        return 'no its all bad';
}

tryIf( );
“ yeah its true”

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

what does the == operator do?

A

it checks to see if the variable name contains the same value as the value supplied on the right side of the equality operator ?

x = 12;
12
x
12
x == 10
false

<b> It checks to see if they are equal regardless of data type (type conversion) </b>

3 == 3
true
3 == '3'
true
typeof 3
"number"
typeof '3'
"string"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
Q

what does the === operator do?

A

it checks to see if the contents of the left and right have not only the same value but also the same data type. <b>(doesn’t perform data conversion)</b>

3 === 3
true
3 === ‘3’;
false

typeof 3
“number”

typeof ‘3’
“string”

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

what is the name of the == operator ?

A

the equality operator

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

What is the name of the === operator ?

A

the strict equality operator

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

what is the name of the != operator?

A

the inequality operator

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

what does the inequality operator do?

A

it checks to see if both sides of the inequality operator are unequal regardless of data type. <b>( performs data conversion)</b>

if the sides are equal than the return is false, if they are unequal the return is true.

x=7;
7

y = 8;
8

x != y
true

x != x
false

<b> This also ignores data type, just like the equality operator. So, here we are looking for the return of false indicating that the number data type and the string data type are correctly being attributed the same value. A true statement means they aren’t the same value which doesn’t indicate that data type conversion is happening. </b>

3 != 3
false
3 != ‘3’
false

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

What is type conversion?

A

When one data type gets turned into another in order to perform its function

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

What is the name of the !== operator?

A

Strict Inequality Operator

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

What does the strict inequality do?

A

it does the exact same thing as the strict equality operator but it looks to see if the values are not equal to produce a true result - and if they are equal to produce a false

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

What is the greater than operator?

A

>

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

what is the greater than or equal to operator?

A

> =

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

How do we use a function to create and execute word blanks?

A

we use a simple function/parameter program :

function wordBlanks(noun, adjective, verb)

{
 var result = 'The ' + adjective + " " +  noun + " "  + verb + ' all the way to the bank'
 return result;}

console.log(wordBlanks(‘fast’, ‘boy’, ‘laughed’));

The boy fast laughed all the way to the bank

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

What is the second thing we need to create a function?

A

The function name

function nameFunc

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

What is the third thing we need to create a function?

A

a set of parens after the function name

function nameFunc ( )

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

What is the first thing we need to create a function?

A

The keyword “function”

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

What is the 5th thing we need to create a function?

A

code inside the curly brackets, that will run anytime the function is called into action.

function nameFunc ( ) { 
console.log('write this in console')
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
107
Q

what is declaring a variable?

A

giving it a variable name

var myName

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

what is assigning a variable?

A

giving the variable name a value

myName = ‘rashaan’

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

What is the 4th thing we need to create a function?

A

curly brackets

function nameFunc ( ) { }

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

what is the lesser than operator?

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

what is the lesser than or equal to operator?

A

<=

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

How do we write the ‘And’ Logical Operator?

A

with double ampersands

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

What does the ‘And’ Logical Operator do?

A

It checks to see if both statements on either side of the operator are true. If one or both sides of the operator return false the whole statement will be false

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

How do we write the ‘OR’ Logical Operator?

A

||

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

What does the ‘OR’ Logical Operator do?

A

It checks to see if at least one of the expressions one either side of the logical operator are true, if at least one side of the operator is true than the whole expression is true.

x = 23
y = 55

x === 23 || y === 2;
true

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

How should we think about what a if statement is saying?

A

If this ….. do that

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

How should we think about what an Else If statement is saying?

A

And if also this…… then do that too

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

How should we think about an Else statement?

A

If none of that…… then just do this instead

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

what should we keep in mind in regards to order when we are running if/else if/else statements?

A

The code stops running at its first true, so the order is important.

function test(val){
    if ( val < 10){
        return 'less than ten';
    }
    else if (val < 5){
        return 'less than five';
    }
}

test (3);
“less than ten”

<b> Notice that the value that was returned was “less than ten” because 3 is less than 10 which is true, but its also less than 5 – but that result did not run… this is because once the first true is found, the code stops running. Its important that we write our code to get the most precise version of what we want in our code. </b>

function test(val){
    if ( val < 10){
        return 'less than five';
    }
    else if (val < 5){
        return 'less than ten';
    }
}

test(3);
“less than five

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

What can we use instead of chained if statements?

A

switch statements

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

What is a switch statement and what does it do?

A

it tests the value and has many case values that define many possible values

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

What is the syntax of a switch statement with 3 cases?

A
function learnSwitch(val){
    var output = "";
    switch(val){
        case 1:
            output = 'a';
            break;
        case 2: 
            output = 'b';
            break;
        case 3:
            output = 'c';
            break;
        default:
            output = 'unfound';
            break;
    }
    return output;
}

learnSwitch(1);
“a”
learnSwitch(2);
“b”

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

What does the break keyword do in a switch statement?

A

it stops the code from running when it finds a match and jumps outside of the statement and continues running the rest of the code

124
Q

If statements are good to be used when?

A

when there limited number of possibilities to be returned, like true/false

125
Q

Switch statements are good to be used when ?

A

when you have code that has a lot of different possibilities or outcomes that are possible

126
Q

if we use a const keyword to create a variable containing an array, can we still modify it with push and pop? shift and unshift methods?

A

yes you can, it will not come up as an error, it will add the values without error.. But if you try to take the variable name and apply it to a different data type or a different/empty array it will come up as an error

127
Q

what do we use the .slice( ) method for on an array?

A

its kinda like pop and shift, where it takes off part of the original array and creates a new array out of it. The difference with slice is that it doesnt have to be the beggining or the ending of an array. You can set where the new array begins and ends - note that the last index point isnt counted

128
Q

what happens if you use .slice( ) with no arguments?

A

it copies the whole array

129
Q

what is .sort ( ) used for in an array?

A

to sort the elements inside of the array

130
Q

when we use sort( ) with arrays that contain strings?

A

it sorts them by alphabetical order

131
Q

what happens when you use .sort ( ) . reverse( )?

A

it reverses order that the array is sorted in

132
Q

what happens when we use .sort( ) on arrays with numerical elements?

A

it sorts them, but not in the way that you think, all 1’s are sorted, then all 2’s , then all 3’s and so on.

1, 13, 145, 20, 27, 275, 29000, 3, 32

notice 145 come before 20 - this is because 145 starts with 1 and one comes before the digit 2….it sorts in the same way an alphabetical sort happens - meaning it doesn’t consider the value

133
Q

can .reverse( ) be used on an array by itself?

A

yes it can, it doesn’t need to be used with .sort

134
Q

how do we put a numerical array in numerical order?

A

array.sort(function(a,b){

return a - b});

135
Q

how do we put a numerical array in a descending numerical order?

A

you switch the position of a - b in the sort function

136
Q

what are anonymous functions?

A

functions that have no function name

137
Q

what does .map( ) do?

A

it creates a new array by applying a function individually to every single element in the array.

function double(num){
    return 2 * num };
const myNumbers = [1,2,3,4];
const doubledNumbers = myNumbers.map(double);

doubledNumbers;
(4)[2, 4, 6, 8]

138
Q

example of using arrays and .map( ) to create html lists and ul tags

A

const steps = [ ‘wash’, ‘rinse’, ‘repeat’];

const stepsElements = steps.map(function(step) {
  return `<li>${step}</li>`;
});
console.log(`<ul>${stepsElements.join('\n\t')}</ul>`);
// <ul>
//   <li>wash</li>
//   <li>rinse</li>
//   <li>repeat</li>
// </ul>
139
Q

What does .foreach( ) do?

A

like .map ( ) it also applies a function to each element of an array, the difference is – is that it doesn’t return the elements in an array.

const directionsLibrary = [‘wash’, ‘rinse’, ‘repeat’];

function saveDirectionInDatabase(direction) {
  // save the direction in the database
  console.log(direction);
}
directionsLibrary.forEach(saveDirectionInDatabase); // ->
// 'wash'
// 'rinse'
//'repeat'
140
Q

what does the .filter( ) method do?

A

This method is used to take one array of items and make a new one that contains only items that a filtering function returns true for.

function isEven(num) {
  return num % 2 === 0;
}

const myNumbers = [1, 2, 3, 4, 5, 6];

const evens = myNumbers.filter(isEven);
console.log(evens); // => [2, 4, 6]
141
Q

what does the .reduce( ) method do ?

A

The reduce ( ) method reduces all the elements in an array into a single value. This is regardless of data type

function sum(total,num){
    return total + num;};

array = [ 1, 3, 4, 6]
(4)[1, 3, 4, 6]
array.reduce(sum);
14

or

newArray = [‘jerry’, ‘dave’, ‘larry’]

newArray.reduce(sum);
“jerrydavelarry”

142
Q

what is a default statement in a switch statement?

A

is where you can set a default return value for a switch statement in the event none of the other case options are found

143
Q

What can you do if you want multiple case options to return the same value?

A

just do not use the break in between those different cases

switch(x){
case 1:
answer: blah blah blah
break;
case 2:
case 3: 
answer: more blah blah 
break;
case 4:
answer: final blah blah blah 
break; }
return x
}

In this code, 2 and 3 will return the same input, if its two it will pass along til the third and give the output as if it were case 3

144
Q

Do we need to use number values for assigning a case in a switch statement?

A

No we do not we can use strings too

case: “bob”

works just fine

145
Q

What do we use .find ( ) for?

A

We use it to find the first element in an array that turns back a true statement..

function isEven(num) {
  return num % 2 === 0;
}
const Numbers = [1, 3, 4, 5, 6];
Numbers.find(isEven); 

4..

146
Q

What happens when you use .find ( ) and none of the elements return a true statement?

A

It returns an undefined statement

147
Q

when you add an item to an array and return the expression containing the .pop( ) what does it return?

A

it returns the length of the new array – not the actual array itself

148
Q

how do you return the actual array after modifying it in some way?

A

call, return or console.log the actual name of the array

149
Q

what should we keep in mind when we want a function to return a true or false statement?

A

all comparison operators return a true or false statement so sometimes instead of using if statements we can just use a comparison operator instead if applicable

150
Q

what do all comparison operators return?

A

a boolean value … true or false

151
Q

in what way are objects different than arrays when it comes to accessing data?

A

objects use properties to access data instead of indexes

152
Q

if arrays are enclosed by brackets, what are objects enclosed by?

A

curly brackets

<b> Array </b>

array = [ ]

<b>Object</b>

object = { }

153
Q

In an object, what goes before the colons?

A

the properties

var myDog = {
"name" :
154
Q

in an object, what goes after the colons?

A

the values to the properties

var myDog = {
"name": "Rex",
155
Q

what data types can be values of an object?

A

any data type in javascript

156
Q

What is Dot Notation?

A

Dot notation is a way to access an objects property value, by its property.

var testObj = {
    "hat": "ballcap",
    "shirt": "jersey",
    "shoes": "cleats"
};
testObj.hat
"ballcap"
testObj.shirt
"jersey"
testObj.shoes
"cleats"
157
Q

what do we put between different property/value pairs on an object?

A

a comma

158
Q

what is the syntax of dot notation?

A

objectName.propertyname

159
Q

how do we use bracket notation to access an object?

A

we use it the same way we would with an array

testObj[“hat”]

160
Q

when must we use bracket notation over dot notation when accessing data of an object?

A

when the property name has a space in it

161
Q

How can we assign a variable name to a object property value? whats the syntax?

A

by using bracket notation or dot notation

var newValueName = objectName[propertyName}

var newValueName = objectName.propertyName

162
Q

Can we assign a variable name to an object property value using both dot notation and bracket notation?

A

yes we can

163
Q

how can we update object properties using dot notation?

A

objectName.PropertyName = “new property name”

<b> Example </b>

nfl = { 
    packers : 'farve',
    niners : 'montana',
    pats : 'brady'
};

nfl.packers = ‘rodgers’

nfl
{packers: “rodgers”, niners: “montana”, pats: “brady”}

164
Q

how can we update object properties using bracket notation?

A

objectName[“propertyName”] = “new value”

nfl
{packers: “rodgers”, niners: “montana”, pats: “brady”}

nfl[“niners”] = “rice”

nfl
{packers: “rodgers”, niners: “rice”, pats: “brady”}

165
Q

how do we delete a property from an object?

A

by using the delete keyword

nfl
{packers: “rodgers”, niners: “rice”, pats: “brady”}
delete nfl.pats

nfl
{packers: “rodgers”, niners: “rice”}

166
Q

how do we check to see if a object has a particular property?

A

objectName.hasownproperty(propertyname)

nfl
{niners: “San Francisco”, packers: “Green Bay”, raiders: “Oakland”, lions: “Detroit”, Giants: “New York”,…}

nfl.hasOwnProperty(‘niners’);
true

167
Q

what does a .hasownproperty( ) return?

A

a boolean value – true or false

168
Q

what to objects allow us to do?

A

allows us to store flexible data

169
Q

can we put an object inside of an array?

A

yes we can

170
Q

how do we access nested objects?

A

use dot notation

var house = {
    "bedroom" : {
        "inside": "bed",
        "outside": "stairs"},
    "livingroom" : {
        "inside" : "stove",
        "outside" : "dining room"}
};
<b> examples </b>
house.bedroom.inside
"bed"
house.bedroom
{inside: "bed", outside: "stairs"}
house
{bedroom: {…}, livingroom: {…}}
171
Q

How do you access a nested object if one of the properties has a space in it?

A

use bracket notation on that property.

var house = {
    "bedroom" : {
        "inside": "bed",
        "outside": "stairs"},
    "living room" : {
        "inside" : "stove",
        "outside" : "dining room"}
};

house[“living room”].inside

“stove”

172
Q

can we use dot notation in conjunction with bracket notation when you have objects nested inside of arrays?

A

yes you can

var myPlants = [
    {
        type: "flowers",
        list: [
            "rose",
            "tulip",
            "dandelion"
            ]
    },
    {
        type: "trees",
        list: [
            "fir",
            "pine",
            "birch"
            ]
    }
    ];

myPlants[1].list[1];
“pine”
myPlants[0].list[2]
“dandelion”

173
Q

what is a loop?

A

loops allow you to run the same code multiple times

174
Q

what is a while loop?

A

a while loop runs while a specified statement is true and stops once its no longer true

for example

var myArray = [ ]
var i = 0

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

myArray
(5)[0, 1, 2, 3, 4]

<b> we set the i variable to zero and used the push method to add it to myArray. Then we used ++ to increase it by one every time it got ran in a loop. Then we set it to <5, so it increased by one until the statement was no longer true, ie until it was no longer less than 5. This leaves us with a 5 character array increasing by one digit under the total value of 5 </b>

175
Q

what are the 4 parts of a for loop?

A
  1. the initialization
  2. the condition
  3. the final act
  4. the actual code ran
176
Q

what part of the for loop happens before any other part of the code runs?

A

the initialization.

this is the starting point of the loop

177
Q

what is the second part of the for loop for?

A

as long as this part returns as true, the loop will keep going

178
Q

what is the final act in the for loop?

A

this one says what will actually happen in the loop

179
Q

an example of how to use the for loop

A
var touchdown = [];
undefined
for (s = 7; s < 63; s++){
    touchdown.push(s);
};
56
touchdown
(56)[7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62]
180
Q

when should we use for loops?

A

when we have a code we want to run a set number of times

181
Q

when should we run a while loop instead of a for loop?

A

when we dont have a set number of times that we want to run a code, but we want to run it as many times as possible until the condition is no longer true

182
Q

if in a while loop there is a condition that will always true how would the code ever get out of running it?

A

it will stop running if there is an if statement that has a statment that runs as true and then a break statement after it. this true if statement and this break statement will break it out of the loop

183
Q

what is variable scope?

A

Variable scope defines how the variables you declare either can or cannot be accessed at different places in your code..

184
Q

variables using the keyword ‘let’ and ‘const’ have what two different types of scope?

A

Global and Block

185
Q

What does it mean when a variable has global scope?

A

it is available everywhere in your code

186
Q

Any variable that is declared outside of a function gets what type of scope?

A

it gets global scope

187
Q

what is block/local scope mean?

A

hat means that it is only accessible within the function’s block of instructions. When the function has finished executing, this new variable disappears.

188
Q

does local or block scope variables affect global scope variables?

A

No they dont

189
Q

what is the scope chain?

A

JavaScript follows the scope chain to determine the value of the variable. First, it looks in the current scope to see if there’s a variable with that name. If that variable name is not defined locally, the JavaScript interpreter will look in the parent scope of the function to see if the variable is defined there, and if it is, it will use that value. The interpreter will continue looking “up” the scope chain until it reaches the global scope, and if it doesn’t find the variable defined there, it will raise an Uncaught ReferenceError indicating that the code refers to a variable that’s not defined.

190
Q

what takes precedence when two variables share a name?

A

when you define a variable in a function that has the same name as a variable in the global scope, the local variable will take precedence over the global one

191
Q

When a local or block scope variable takes precedence over a global scope variable, what is a name that is often used for this process?

A

variable shadowing

192
Q

Does Global scope extend across files?

A

yes it does, meaning you can access it in multiple js files even if it isnt defined in that particular file

193
Q

What is a side effect?

A

A side effect is when a function reaches outside its local scope up into a parent or global scope scope and alters a value that lives there.

194
Q

are side effects always bad?

A

No they are not always bad, as long as they are intended. Unintended side effects are what we want to avoid at all costs

195
Q

A combination of global variables along with unintended side affects almost always guarantees what?

A

that the code becomes indeterminate.

196
Q

What does it mean when code is indeterminate?

A

it is code that — given a single set of inputs — returns one value some times and another at other times. This can lead to frustrating and hard-to-track-down bugs in your code.

197
Q

What does it mean when the code is determinate?

A

is code that will always return the same value if it’s provided with the same inputs.

198
Q

When is a function said to be pure?

A

when it is determinate and has no side effects

199
Q

Should you refer to a global variable name inside of your function?

A

No, if you want to use a variable inside a function, define and assign it inside of your function

200
Q

Should we always use keywords, let or const or var in our functions?

A

Yes , this makes them local/block and wont affect any other variables

201
Q

How to apply strict mode to your java file?

A

‘use strict’;

202
Q

what will setting your java file on strict mode do?

A

When strict mode is enabled, any time a variable is declared without the let or const keyword, an error will be triggered.

203
Q

Why is setting your page to strict mode a good idea to always do?

A

because this keeps your from accidently modifying code that you don’t intend. Like you forget to put a let or const on a block scope variable and accidently make it global and change something you didnt intend

204
Q

what are two ways strict mode can be set?

A

it can be set for the whole page, by placing at the top of the page,

or

it can be set for a specific function, by being placed at the top of a function and like a block scope variable it will start and end within that function

205
Q

what is an object?

A

an object is a complex data structure, used to hold key/value pairs

206
Q

what is a key/value pair? how should we think about a key/value pair?

A

a key/value pair is kinda like a dictionary and its entries

the word is the key and the definition is the value

happy: a feeling of content, not sad

key value

207
Q

what is an object key followed by?

A

a colon :

208
Q

what follows a key/value pair?

A

a comma ,

209
Q

what is an object literal?

A

it is one way of creating an object…

const ledZeppelin = {
  singer: 'Robert Plant',
  guitar: 'Jimmy Page',
  bass: 'John Paul Jones',
  drums: 'John Bonham'
}
210
Q

Do keys need to have quotations when creating a literal object?

A

Most of the time they are not neccesary

211
Q

What are examples of times when quotations will be necessary when creating keys of an object literal?

A

if you need to add a space in the name of a key or if you need to add a period or something to the key

<b> keys with spaces get quotations </b>
const ledZeppelin2 = {
  'lead singer': 'Robert Plant',
  'lead guitar': 'Jimmy Page',
}

<b> keys without spaces or needed punctuation dont </b>

const ledZeppelin = {
  singer: 'Robert Plant',
  guitar: 'Jimmy Page',
  bass: 'John Paul Jones',
  drums: 'John Bonham'
}
212
Q

Can we have multiple keys in an object?

A

No, keys in an object must all be unique — that is, each key can be used only once in the object.

213
Q

What type of data types can be values of an object key?

A

The values in an object can be any valid JavaScript data type. In the example above, all the values are strings, but values can also be numbers, booleans, other objects, null, or functions.

214
Q

what do we call a function when it is used as a value for an object key?

A

When an object has a value that is a function, we refer to that key/value pair as a method.

215
Q

what do we call a function when it is used as a value for an object key?

A

an object method.

When an object has a value that is a function, we refer to that key/value pair as a method.

216
Q

What is another way that you can self reference a key in an object without having to repeat the key itself?

A

by using the ‘This’ keyword

const myFamily = {
  lastName: 'Doe',
  mom: 'Cynthia',
  dad: 'Paul',
  sayHi: function() {
    console.log(`Hello from the ${<b>this</b>.lastName}s`);
  }
};

myFamily.sayHi() // => Hello from the Does

217
Q

When using objects in a function, what do we need to remember about how global scope variable with the same name is affected when it comes to shadowing?

A

objects change the global scope variable when used inside of a function after it is ran.

function myFunc2(obj) {
  obj.foo = 'bizz';
  console.log(obj.foo);
}

const myVar = {foo: ‘bar’};
console.log(myVar.foo); // => ‘bar’
myFunc2(myVar); // => logs ‘bizz’ — that’s what we thought would happen!
<b> console.log(myVar.foo); // => ‘bizz’ — ruh roh! change inside function affected outside world! </b>

218
Q

what should you keep in mind when passing objects as arguments?

A

that there may be unintended side effects in the global scope

219
Q

How do you get keys to an object to show up as an array so you iterate through them?

A

use object.key( ) and place object name inside of the parens

220
Q

How do you get keys to an object to show up as an array so you iterate through them?

A

use Object.keys( ) and place object name inside of the parens

221
Q

What is a factory function? And what is its job

A

a function that returns an object

function createObject( ){
return {
name : dave,
age : 23,
job : wrestler,
}
222
Q

what is the similarity between .map and .foreach?

A

they both act like a loop and iterate through each item of an array applying a particular function to each one

223
Q

what does .foreach return if it doesn’t return an array?

A

it returns ‘undefined’

224
Q

what two ways do we apply a function to a .map or a .foreach?

A

you can write a code beforehand, or if there is one already written in the code…. you can just pass the function name through as an argument.

<b>
 function double(x){
  result = x * 2
  return result
};
</b>

console. log(numbers.map(double));
console. log(numbers.forEach(double));

or you can write an anonymous function inside of the parens

<b>
console.log(numbers.map(function(x){
  newNumbers = x * 3;
  return newNumbers;
})
)
console.log(numbers.forEach(function(x){
  newNumbers = x * 3;
  return newNumbers;
})
)
</b>
225
Q

what do i need to start remembering to do when i create new values for anything….

A

give it a new variable name to access it later

226
Q

what do i need to start remembering to do when it comes to producing/returning values…

A

using return

and/or

console.log( )

227
Q

when you make an anonymous function do you still need to use return to produce the result inside of a parens?.

A

yes you do otherwise it returns as undefined

228
Q

what does ${variable name} allow us to do?

A

it allows us to insert a value (regardless of data type to be inserted in a string of code) by its variable name.

function createString(x){
  return  ` this is a sting  with the word ${x} inside of it`
};

console.log(createString(‘apples’));
this is a string with the word apples inside of it

229
Q

when using anonymous functions to pass arrays with items already set, do we need to pass an argument or arguments when we are writing our code inside the parens?

A

no we don’t, the array already has preset array items that will work work as arguments. This is true for things like .map and .foreach that are already designed to loop or iterate through an existing array

230
Q

do we need to add the array name in the parameter of a function?

A

no you dont, just need a placeholder text

231
Q

when creating a new variable from the result of a function do you need to add the console.log as well?

A

no you do not need to add the console.log - when you want to run it you will have to just put console.log(variableName) later in the code when you want to run it

232
Q

what function do we use with .reduce either anonymously or by passing function name through as an argument?

A
function functionName (a,b){
return a + b}
);

or

array.reduce(function(a,b){
return a + b}
);

233
Q

when accessing a data point in an object by bracket notation, does the key need to have quotations inside of the brackets?

A

yes it does, otherwise it will come up as an error

234
Q

When you need to create a new array within a function how do you do so?

A
  1. Create an empty array
  2. Create a loop.
  3. .push( ) to empty array name
  4. Return array
235
Q

does the footer tag go inside the body?

A

yes it does

236
Q

when using dot notation in accessing objects do we need to use quotations?

A

no you dont, not unless it has spaces

237
Q

when using bracket notation in accessing objects do we need to use quotations?

A

yes we do

238
Q

what type of error will come up if you forget to put a comma in between key/value pairs in an object?

A

unexpected string

239
Q

what do we call things that we add to arrays to modify them? things like .reduce or .sort or .filter or .map?

A

these are called array methods

240
Q

when running a object method (function) what do we need to make sure we include when trying to run it?

A

the parens

const mySquad = {
  name : '49ers',
  city : 'San Francsico',
  record : '8 - 0',
  chant : function(){
    console.log(`Were the ${mySquad.city} ${mySquad.name} Who's got it
    better than US??!!?! NOOOOOOBODY!!!!`);
  },
  'superbowl wins': '5',
};

console.log(mySquad.chant());

241
Q

when running a object method (function) what do we need to make sure we include when trying to run it?

A

the parens

const mySquad = {
  name : '49ers',
  city : 'San Francisco',
  record : '8 - 0',
  chant : function(){
    console.log(`Were the ${mySquad.city} ${mySquad.name} Who's got it
    better than US??!!?! NOOOOOOBODY!!!!`);
  },
  'superbowl wins': '5',
};

console.log(mySquad.chant());

242
Q

what method can you add to a string to make the all the characters in the string upper case?

A

.toUpperCase( )

243
Q

what does the method .trim( ) do?

A

it takes off the spaces at the beginning and end of strings

244
Q

what does the method .toLowerCase( ) do?

A

it makes a string all lowercase

245
Q

can we put more than one method on one a string or object?

A

yes we can, like if we wanted a string to be lowercase and have no spaces on the end you can do something like this

string.toLowerCase( ).trim( )

246
Q

what is it called when we use multiple methods on a string or on a object?

A

its called method chaining

247
Q

what is the .find( ) method?

A

it takes a function and runs it through each item of the array and returns it only if its true.

IT ONLY RETURNS ONE ITEM

248
Q

what does the slice array do?

A

it creates an array from an existing one. You can call it with parameters and add arguments to decide which index points you want to specifically copy

array = [45,6,8,99,62]

array.slice(2,3)
array = [8,99]

249
Q

what happens if you use .slice( ) with no parameters or arguments?

A

it copies the whole array

250
Q

what happens when you use .slice( ) with negative numbers

A

it counts from the end of the array

251
Q

can you use the .length method on both strings and arrays?

A

yes you can use it on both strings and arrays and it will return the character count.

so when trying to access certain items or strings by length you can use this tool on both data types

252
Q

how to create a find max number function without using any built in functions ?

A
function max(numbers){
  let currentValue = numbers[0];
  for ( i = 0; i < numbers.length; i++){
    if (numbers[i] > currentValue){
      currentValue = numbers[i];
    }
  }
  return currentValue;
}
253
Q

if .pop( ) and .push( ) and shift( ) and unshift( ) already have determined items in an array that it targets, how do we specify which items we want to target if not one of these?

A

then we use .slice( )

254
Q

when using the .pop( ) method, do you need to add anything inside of the parenthesis to get it to target which items it will remove?

A

no you dont, it automatically takes off the last item in an array

255
Q

what is something that you can use join( ) for?

A

you can use this to add random things to the end of an array like if you want to make the array vertical and not horizontal you can do this

array.join(‘\n’)
and it will display the array vertically by creating a new line on the end of the items in the array

256
Q

when using the method .hasOwnProperty( ) to search for an object key, do we need to put that key in quotations ?

A

yes we do, otherwise it will return false even if its actually there

257
Q

when using push.( ) to add an array to another array…
what happens if we add the variable name for the second array inside of the parens with quotations?

array.push(“array2”)?

A

it will just actually add the string to the array and not the array it represents.

[‘wash’, ‘rinse’, ‘repeat’, ‘array2’];

258
Q

when using push.( ) to add an array to another array…
what happens if we add the variable name for the second array inside of the parens without quotations?

array.push(array2)?

A

it will add the second array, but as a nested array, not as apart of the first array.

[‘wash’, ‘rinse’, ‘repeat’, [‘dry’,’condition’]];

259
Q

when using push.( ) to add an array to another array…
what happens if we dont add the variable name for the second array inside of the parens and type out the actual items in the array itself?

array.push(“dry”,”condition”)?

A

it will add the actual items to the array without making it a nested array, it will all be one single array

260
Q

when using .slice( ) method we know that the second parameter when using a positive number doesn’t get included in the new array but includes the item before it. Is this the same when using a negative number to count from the end of the array?

A

no, when using a negative number to count from the end of an array, we find that a negative number works exactly like a positive number in the first parameter spot, in that, it includes the item that it represents and doesn’t cut off before it.

261
Q

when using .slice( ) and with a positive number in the first parameter place and then a negative number in the second parameter place, from which way will it create a new array?

A

it will count from the beginning of the array starting from the index represented by the positive number - until it reaches the item represented by the negative number

so it will go from left to right

262
Q

when using a .slice( ) with a negative number only with no positive number in the first parameter position, how does the method copy its array?

A

it counts from the end, until it reaches the item represented by the number and it copies everything from the end to that number

263
Q

when using .slice( ) with a positive number only and no other number in the second parameter spot, how does the array get copied?

A

it starts from the item represented by that number and then copies everything from that until the end of the array

264
Q

when a variable has no value what does it come back as?

A

undefined

265
Q

when a variable has no keyword what does it come back as?

A

not defined

266
Q

when you call a function without the parens what will be returned?

A

[function]

267
Q

what do you need to remember when you’re calling an object method?

A

the parens ( )

268
Q

what happens when you call a object function without parens with either dot or bracket notation?

A

it returns [function]

269
Q

when you call an object method using dot notation where do you put the parens?

A

you put the parens immediately after the name

objectname.keyname( );

270
Q

when you call an object method using bracket notation where do you put the parens?

A

you put the parens after the brackets.

objectnamekeyname;

271
Q

when you use push( ) on an array and console log it with the .push method attached, what does it return?

A

it returns the character length of the array

272
Q

how do you return the actual array after you added an item to it by using .push( )

A

you console.log or return the name of the array itself not with push( )

273
Q

how to create an array without just typing it yourself?

A
create a function
create empty array with name
create for loop
result the push method on to the array name
return array name
274
Q

when accessing objects inside of array using a call back functions in a array method like .map( ), how do we specifically target individual keys inside of the various objects?

A

we give the function a parameter name, then use that dot or bracket notation on that parameter name and then target the desired key.

arrayOfObject = [
{ name : dave,
city : detroit,
brothers : 4,   }, 
{ name : chris,
city : boston,
brothers : 1,   },      
{ name : sarah,
city : memphis,
brothers : 0   },       
]

arrayOfObject.map(function(person){
return person.name};

when we call this function, the map method will automatically
run through each item. When we put person.name inside of the curly brackets, the engine will read that it is a parameter and realize that it is an object key because dot notation only goes on object keys. So when it finds that it will return all the names of each object in a new array, because map returns a new array

275
Q

what does a for/in loop do?

A

loops through the properties or keys of an object

276
Q

when using Object.keys( ) on an object does it change the original object to an array?

A

no the original object will stil be an object?

277
Q

how do we take an object and make it an array and make it accessible later?

A

you create a new variable name and use object.keys( )

var array = Object.keys( )

278
Q

when you use object.keys( ) on an object? what is returned as an array? the keys? the values? both?

A

the keys only

279
Q

if we want to access a specific key in an object? how do we do so ?

A

var newVarName = Object.keys( object)[n];

console.log(newVarName);
key;

280
Q

can you add array methods like .sort( ) and .push( ) to parameter names in anticipation that the parameter passed will be an array or an object?

A

yes you can.

281
Q

what is the answer to the student report drill where you had to take an array of objects and produce an array of strings with student name and grades being returned ?

A
function makeStudentsReport(data) {
  let array = [];
  for (i = 0; i < data.length; i++){
    let item = data[i];
    array.push(`${item.name}: ${item.grade}`)
  }
  return array;
}
282
Q

what is the solution to the enroll in summer school drill where the objective is to take an array of objects and return the name and course as the same as the original objects but change teh status to in summer school using a loop?

A
function enrollInSummerSchoolAlt(students) {
  const results = [];
  for (let i = 0; i < students.length; i++) {
    results.push({
      name: students[i].name,
      status: 'In Summer school',
      course: students[i].course,
    });
  }
  return results;
}
283
Q

what is the solution to the enroll in summer school drill where the objective is to take an array of objects and return the name and course as the same as the original objects but change the status to in summer school WITHOUT using a loop?

A
function enrollInSummerSchool(students){
  return students.map(function(student){
    return {
    name : student.name,
    status : 'in summer school',
    course : student.course}

})
}

284
Q

When using dot or bracket notation on one of an object’s keys - what will be returned?

A

The value of that key.

285
Q

what is the answer to the findbyID drill where the objective is to look in an array of objects and create a fucntion with two parameters, one paremeter is the array of objects and the second parameter is the idNum that were looking for. We want to find the item inside all the objects that has a particular idNum

A
function findById(items, idNum) {
  return items.find(function(item){
   return item.id === idNum
  });
}
286
Q

what is the answer to validate keys drill , where the objective is to create a function with two parameters, one parameter is an object, the second parameter is the ‘expected keys’ you want to find in the object.

validateKeys should return true if object has all of the keys from expectedKeys, and no additional keys. It should return false if one or more of the expectedKeys is missing from the object, or if the object contains extra keys not in expectedKeys.

A
function validateKeys(object, expectedKeys) {
  if (Object.keys(object).length !== expectedKeys.length) {
    return false;
  }
  for (let i = 0; i < expectedKeys.length; i++) {
    if (!Object.keys(object).find(key => key === expectedKeys[i])) {
      return false;
    }
  }
  return true;
}
// if there's not the same number of object keys
  // and expected keys, then we know there are missing or
  // extra keys, so return false
 // we iterate over each expected key and verify that
  // it's found in `object`.
 // if we get to this point in our code, the keys are valid
  // so we return `true`
287
Q

when creating a function that creates an array, there is a point where you will use the push method on to the array name. During this, do we need to add the ‘return’ key?

A

No, using the ‘return’ key at this point will not return an array, even if the rest of the code is correct.

use the ‘return’ key on the array name after push has been used.

288
Q

when using a function to create an array, when do we put the ‘return’ key in the function to produce an array?

A

use the ‘return’ key on the array name after push has been used.

not on the .push( ) method

289
Q

when ever you need to create a loop and increment or decrement by more than i++ or I–, how do we structure the third and final part of the loop?

A

with compound assignment operators

i += 10

290
Q

why must we use compound assignment operators when creating loops that increase or decrease by more than one?

A

because when you use a compound assignment operator, the variable (i) gets saved as the new value, and then runs in the loop again.

when you just use + or something, the loop goes back to where ever the original variable started ( i = 0), meaning that the loop will just keep looping and never be terminated because it will never reach the second part of the loop ( < array.length). meaning it wont produce anything and will just run and run.

291
Q

Can you use bracket notation on the object name itself?

A

No, you can use it on the keys and the values but you cannot use it on the object name itself.

[object]name will not work;

you would have to go
object[‘name’]
or
object.name

292
Q

How can you take a float number (with decimals) and round it down to the whole number?

A

Save the number to a variable name

Use Math.floor(variable name) on that variable

293
Q

How do you find the index of an array using an array method?

A

Use

indexOf( array name )

294
Q

Why would you use an array method to find the index of an array item instead of just counting?

A

Because you don’t always know what’s in an array, or an array might to be too big to count

295
Q

Does indexOf( ) tell you every occurrence of the searched for array item?

A

No it only tells you the location of the first occurrence

296
Q

What if you know the index of an item in an array but want to see the index of others or another later in the array?

A

Use index of method, put item value you’re looking for and select what index method you want it to start counting from.

animals.indexOf(‘dog’,10)

This will look for the first item named dog in the array named animals starting from counting at index 10. Any item named dog before index 10 of animal array will be ignored

297
Q

What happens if you use, indexOf( ) and search an array item that isn’t present in the array you are looking in?

A

It will return the index of -1

298
Q

when you use shift on an array what does it return?

A

it returns the value of the item that has been removed off of the front of the array

299
Q

How can we check to see if an array has a particular item in its array?

A

array.includes( )

300
Q

Can we check if an item is in an array, beginning from a certain point?

A

Yes,

array.includes( item, 2)

This will start looking from index position 2

301
Q

How do you add two arrays together so they become one and are not nested in one another?

A

array.concat(‘array2’)

302
Q

How to return the character code of a character?

A

Character.charCodeAt( );

e.charCodeAt( );

303
Q

What does the ** operator do?

A

It multiplies by the power of..

5**2

Is 5 to the second power.

304
Q

How do we check the data type of a variable?

A

By using ‘typeof’

typeof variable name

305
Q

How do we make a parameter or any form of input case INSENSITIVE ?

A

Add .toLowerCase() to the parameter and/or the input to change the whole string to lower case and make it so the typing of CASE doesn’t matter