JAVASCRIPT Flashcards

1
Q

What is the purpose of variables?

A

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

=

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

number, letter, underscore, $

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

lowercase and uppercase matters

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

store letters

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

store numerical 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

true/false used to make decisions

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

assign

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 a 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

undefined: no value assigned
null: set to nothing

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

to know what you are actually logging

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

Give five examples of JavaScript primitives.

A

number, string, 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

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

addition of numbers and concatenation of strings

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

assigns the value of the variable to the previous value plus right-side of operator

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

What are objects used for?

A

store multiple types of data that are related

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

What are object properties?

A

variables glued to objects

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

Describe object literal notation.

A

{key: value}

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

delete operator

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

object.property (dot notation)

object[‘property’] (square bracket notation)

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

What are arrays used for?

A

store data in order

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

Describe array literal notation.

A

var array = [ ]

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

numeric indexes vs named properties

arrays have order

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

0

28
Q

What is the length property of an array?

A

number of items in the 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 set of statements that performs a task or calculates a value

31
Q

Describe the parts of a function definition.

A
  1. function keyword
  2. optional name
  3. zero or more parameters in ( ) separated by commas
  4. code block { }
  5. optional return statement inside code block
32
Q

Describe the parts of a function call.

A
  1. functions name

2. zero or more arguments in ( ) separated by commas

33
Q

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

A

function calls do not have code blocks or keyword

34
Q

What is the difference between a parameter and an argument?

A

parameters are placeholders in a function definition

arguments are actual data in a function call

35
Q

Why are function parameters useful?

A

reusability and variability

36
Q

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

A

causes the function to produce a value

also exits the function; no code after the return statement is executed

37
Q

Why do we log things to the console?

A

so we can keep track of our data as we change it

38
Q

What is a method?

A

a function

39
Q

How is a method different from any other function?

A

function which is a property of an object, static and instance

40
Q

How do you remove the last element from an array?

A

array.pop( )

41
Q

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

A

Math.floor( )

42
Q

How do you generate a random number?

A

Math.random( )

43
Q

How do you delete an element from an array?

A

array. pop( ) end
array. shift( ) start
array. splice( ) anywhere

44
Q

How do you append an element to an array?

A

array. push( ) end

array. unshift( ) start

45
Q

How do you break a string up into an array?

A

string.split( )

46
Q

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

A

no. log to console before and after method

47
Q

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

A

no

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

, <=, >=, ==, ===

50
Q

What data type do comparison expressions evaluate to?

A

boolean

51
Q

What is the purpose of an if statement?

A

to make decisions

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 (condition) {codeblock}

54
Q

What are the three logical operators?

A

&&AND ||OR !NOT

55
Q

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

A

$$ ||

56
Q

What is the purpose of a loop?

A

to repeat the same, or similar, code a number of times

57
Q

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

A

to stop the loop

58
Q

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

A

each time the loop runs

59
Q

When does the condition expression of a loop get evaluated?

A

before each iteration

60
Q

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

A

once, when the loop begins

61
Q

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

A

after each iteration

62
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

63
Q

What does the ++ increment operator do?

A

increments (adds one to) its operand and returns a value

64
Q

How do you iterate through the keys of an object?

A

for in loop

65
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

defined

66
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closures