JS 1 Flashcards

1
Q

What is the purpose of variables?

A

variables are assigned data, and allow for referring to them later to access that 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” or “let” keyword followed by the name

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

variable name, equal sign, followed by value assigned

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

numbers, letters, _, $

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

case (lowercase/uppercase) needs to be exact, since they are differentiated in javascript

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

a string is made up of characters in a row and is used to store text

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

a number is for numeric value and used in mathematical operations

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

booleans allow for the ability to make decisions based on true or false

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

the assignment operator allows for assigning a value to a variable

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

variable name, then equal sign, followed by new value

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
  • null is assigned to a variable which should be purposefully empty for now
  • undefined is accidentally empty, assigned by computer when no value is provided
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

helps to know where the information is coming from, helps other developers

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

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

number

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

What is string concatenation?

A

combining strings with the plus 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

adding numbers or combining strings (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

adds the result of the right side plus the left side and replaces the left side

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

What are objects used for?

A

store key/value collections of data, as well as methods relevant to that object

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

What are object properties?

A

the association between a key and a value, or the equivalent of a variable stored in an object

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

Describe object literal notation.

A

a way to initialize an object using the left curly brace and right curly brace, with optional properties nested inside

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

How do you remove a property from an object?

A
  • use the delete operator to remove the property completely

- assign to empty string to remove the value only

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

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

A
  • dot notation: object name, dot, property key

- bracket notation: object name, brackets enclosing quotation marks enclosing property key

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

What are arrays used for?

A

arrays store lists of information

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

Describe array literal notation.

A

square brackets surrounding the data strings

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

How are arrays different from “plain” objects?

A

arrays are ordered by number, objects have property names

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

What number represents the first index of an array?

A

zero

28
Q

What is the length property of an array?

A

number of elements in an array

29
Q

How do you calculate the last index of an array?

A

array.length - 1

30
Q

What is a function in JavaScript?

A

a reusable container of code which performs actions

31
Q

Describe the parts of a function definition.

A

function keyword, function name, parameters surrounded by parenthesis, code block, optional return statement

32
Q

Describe the parts of a function call.

A

function name, arguments surrounded by parenthesis

33
Q

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

A

A function definition is the creation/declaration of the function with a function keyword and code block, while a function call is running/invoking an already created function.

34
Q

What is the difference between a parameter and an argument?

A

A parameter takes in arguments. Parameters are placeholders in a function’s definition, while arguments are values used in a function’s call.

35
Q

Why are function parameters useful?

A

Parameters allow for performing actions on different data of the same type when the function is invoked multiple times.

36
Q

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

A

a return statement exits the code block and allows the called function to evaluate to the returned value

37
Q

Why do we log things to the console?

A

to see an output to help debugging in development

38
Q

What is a method?

A

a function in an object

39
Q

How is a method different from any other function?

A

a method is specific to an object, so have to specify object name with method

40
Q

How do you remove the last element from an array?

A

.pop() method

41
Q

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

A

Math.floor() method

42
Q

How do you generate a random number?

A

Math.random() method

43
Q

How do you delete an element from an array?

A

.splice() method with first arg being index and second arg being number of items to remove

44
Q

How do you append an element to an array?

A

.push() method

45
Q

How do you break a string up into an array?

A

.split() method with argument being what character(s) you want to split with

46
Q

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

A

No, MDN documentation

47
Q

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

A

not always

48
Q

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

A

MDN

49
Q

Give 6 examples of comparison operators.

A
< Less than operator.
> Greater than operator.
<= Less than or equal operator.
>= Greater than or equal operator.
!== strict inequality operator
=== strict equality operator
50
Q

What data type do comparison expressions evaluate?

A

boolean

51
Q

What is the purpose of an if statement?

A

check a condition to make choices

52
Q

Is ‘else’ required in order to use an if statement?

A

no

53
Q

Describe the syntax (structure) of an if statement.

A

if keyword, then condition in parenthesis, then body in curly braces

54
Q

What are the three logical operators?

A

&& and operator
|| or operator
! not operator

55
Q

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

A

use logical operators (&&, ||) in between the expressions

56
Q

What is the purpose of a loop?

A

repetition

57
Q

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

A

to see if the loop should stop

58
Q

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

A

an instance of repeating the code block

59
Q

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

A

before the while loop body runs

60
Q

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

A

first

61
Q

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

A

after initialization, but before code block runs

62
Q

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

A

at the end of each iteration

63
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 keyword

64
Q

What does the ++ increment operator do?

A

increases value of operand by 1

65
Q

How do you iterate through the keys of an object?

A

for / in loop