Javascript p1 Flashcards

variables to loops

1
Q

What is the purpose of variables?

A

temporarily store data

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

How do you declare a variable?

A

var, let, const

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

How do you initialize (assign a value to) a variable?

A

= assignment operator

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

What characters are allowed in variable names?

A

letters, numbers, $ and _

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

What does it mean to say that variable names are “case sensitive”?

A

same var name in upper and lowercase are two dif variables

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

What is the purpose of a string?

A

to manage text data

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

What is the purpose of a number?

A

to manage numeric data

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

What is the purpose of a boolean?

A

to work with true/false, yes/no, on/off states

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

What does the = operator mean in JavaScript?

A

assignment, this var is that value

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

How do you update the value of a variable?

A

reassign it

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

What is the difference between null and undefined?

A
    • undefined has been declared and is unused (empty field)

- - null is intentionally empty

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

so you know exactly what you’re looking at

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

Give five examples of JavaScript primitives.

A

string, number, boolean, null, undefined, symbol, bigint

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

What data type is returned by an arithmetic operation?

A

numeric

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

What is string concatenation?

A

combining strings using the + operator

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

What purpose(s) does the + plus operator serve in JavaScript?

A
    • combining the values it’s between

- - arithmatic & string concatenation

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

What data type is returned by comparing two values (, ===, etc)?

A

boolean

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

What does the += “plus-equals” operator do?

A

combines given values and reassigns to original variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
code read: 
var area = width * height;
A

there’s the expression width * height, and the result of that expression is being assigned to the variable area

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

code read:

motto += ‘ is the goat’;

A

the string ‘ is the goat’ is being concatenated with the variable motto and the result is being reassigned to the variable motto

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

What are objects used for?

A
    • creating models of things
    • conceptualizing an idea of a thing by listing it’s attributes as properties/keys with values, so that information about it can be accessed or manipulated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are object properties?

A

the variables that make up the object

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

Describe object literal notation.

A

– declare var name, assign it to curbrace enclosed list of comma-separated key:value pairs

var object = {
property/key: 'value',
property/key: 'value',
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do you remove a property from an object?

A
    • delete object.property/key;

- - delete object[‘property’];

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

What are the two ways to get or update the value of a property?

A
    • object.property = ‘newValue’; (dot notation)

- - object[‘property’] = ‘newValue’; (square bracket syntax)

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

code read:
var object = {
property: value
}

A

there is a new object literal being assigned the variable object, with the property property assigned the value value

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

What are arrays used for?

A

storing a list of values

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

Describe array literal notation.

A

var array = [item01, item02, item03];

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

How are arrays different from “plain” objects?

A

list of index#/value pairs, not a list of key/value pairs

30
Q

What number represents the first index of an array?

A

0 zero

31
Q

What is the length property of an array?

A

array.length

32
Q

How do you calculate the last index of an array?

A

(array.length - 1)

33
Q
code read:
var colors = ['red', 'white', 'blue'];
A

there is an array literal being defined with the values of string red, string white, and string blue and assigned to the variable colors

34
Q

What is a function in JavaScript?

A
    • a bundle of code which takes arguments and processes them in some manner
    • repeatable code we can call anytime
35
Q

Describe the parts of a function definition.

A

function keyword, name (optional), parameters, code block, return statement (optional)

36
Q

Describe the parts of a function call.

A

function name, argument(s)

37
Q

When comparing them side-by-side, what are the differences between a function call and a function definition?

A
    • call is small, definition has a codeblock

- - function keyword + parameters vs function’s name + arguments

38
Q

What is the difference between a parameter and an argument?

A
    • parameter is where arguments go

- - parameter = placeholder, argument = actual

39
Q

Why are function parameters useful?

A

declares/defines potential arguments

40
Q

What two effects does a return statement have on the behavior of a function?

A
    • causes the function to produce a value

- - exists the function

41
Q
code read:
function \_\_\_(\_\_\_) {
var \_\_ = \_\_\_ * 2;
return \_\_\_;
}
var \_\_\_ = \_\_\_(\_\_\_);
A

line one, there is a function being defined named ___, it takes a single parameter of ___, then the opening curbrace for the codeblock.
line two, there’s the expression ____, the result being assigned to var ___.
line three, ___ is being returned.
line four, closing curbrace.
line five, the ___ function is being called with the single argument of ____, and the return is being assigned to the variable ___.

42
Q

Why do we log things to the console?

A

to see what we’re doing

43
Q

What is a method?

A
    • a function that’s a property of an object

- - an object reference to a function

44
Q

How is a method different from any other function?

A
    • it’s unique to it’s object ?

- - .method() instead of function()

45
Q

How do you remove the last element from an array?

A
    • .pop() removes last and returns it

- - .shift() removes first

46
Q

How do you round a number down to the nearest integer?

A
    • .floor()

- - math.round()

47
Q

How do you generate a random number?

A
    • math.random()

- - math.floor(math.random() * max)

48
Q

How do you delete an element from an array?

A

.splice(start, deleteCount, item1, item2…)

myArray.splice(start, deleteCount) actually removes the element, reindexes the array, and changes its length.

delete myArray[0]
delete will delete the object property, but will not reindex the array or update its length. Note that it is not in fact set to the value undefined, rather the property is removed from the array, making it appear undefined.

49
Q

How do you append an element to an array?

A
    • .push() adds to the end of an array

- - .unshift() adds to beginning of array

50
Q

How do you break a string up into an array?

A
    • .split(‘’)

- - .join(‘’)

51
Q

Do string methods change the original string? How would you check if you weren’t sure?

A
    • no

- - console.log(string)

52
Q

Roughly how many string methods are there according to the MDN Web docs?

A

lots, 50+

53
Q

Is the return value of a function or method useful in every situation?

A

no

54
Q

Roughly how many array methods are there according to the MDN Web docs?

A

lots, 50+

55
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

Mozilla Dev Network

56
Q

Give 6 examples of comparison operators.

A
    • > greater than
    • < less than
    • > = greater than or equal to
    • <= less than or equal to
    • == equal
    • === strictly equal value & type
    • !== not equal value or type
    • != not equal
57
Q

What data type do comparison expressions evaluate to?

A

boolean (t/f)

58
Q

What is the purpose of an if statement?

A

– to do a thing if a condition is met, otherwise do something else

The if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed.

59
Q

Is else required in order to use an if statement?

A

no

60
Q

Describe the syntax (structure) of an if statement.

A
if (condition) {
statement1
} else {
statement2
}
61
Q

What are the three logical operators?

A
    • AND &&
    • OR ||
    • NOT !
62
Q

How do you compare two different expressions in the same condition?

A

using logical operators

63
Q

What is the purpose of a loop?

A

to iterate/loop through data, such as an array

64
Q

What is the purpose of a condition expression in a loop?

A

to determine whether to execute the statement

65
Q

What does “iteration” mean in the context of loops?

A

to increase an initial value, run a check using that value, then progress to next value and repeat

66
Q

When does the condition expression of a while loop get evaluated?

A

before each loop, before executing the statement

67
Q

When does the initialization expression of a for loop get evaluated?

A

once at the start

68
Q

When does the condition expression of a for loop get evaluated?

A

at the start of each loop

69
Q

When does the final expression of a for loop get evaluated?

A

before the condition is evaluated

70
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

71
Q

What does the ++ increment operator do?

A

adds +1 to the expression

72
Q

How do you iterate through the keys of an object?

A

for (const property in object)

– for…in loop