JAVASCRIPT Flashcards

1
Q

What is the purpose of variables?

A

to have data and store it to possibly use it later
make a piece of code mostly permanent

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

How do you declare a variable?

A

Using keywords such as “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

using an equal sign (=)

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, dollar sign, or underscore (_)
cannot start a variable with a number

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 does not equal Case

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 text information

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

numbers are for math

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 test for conditionals - only use the variable TRUE or FALSE
allows us to make a decision
without booleans –> you don’t get to do another way of branching others

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

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

assigning a new value on the same variable on a different line as long as the keyword, var was used because const cannot be changed because its constant
Don’t need another var on the next line. Just need to do variable = 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 –> indicator that it’s empty but plan to place something there –> purposeful emptiness –> declared by a developed –> needs to assign to a variable

undefined –> accidental emptiness –> declared by javascript language –> NEVER use this

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 ensure clarity and know what the value is assigned to. trying not to mistake that this value is not coming from another place.

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

Putting two or more strings together to form a phrase or a sentence

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

allows a number or string to add to the variable to the right and produces a single value

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

What are objects used for?

A

to group multiple variables and functions to describe something
to create a box that holds multiple variables that is related to each other

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

What are object properties?

A

individual property data within a data

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

Describe object literal notation.

A

has property:value pairs with a comma separating it

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 object.property

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 or square bracket notation
object.property OR object[‘property’]

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

What are arrays used for?

A

to store any list of information – > order may be extremely important or may not be

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

Describe array literal notation.

A

keyword with a variable equal to a square bracket and the list is separated by a comma

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 –> all the same datatype & length property is present
objects –> different datatype, bunch of different things

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

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

What is the length property of an array?

A

it calculates how many values they are in an array

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

How do you calculate the last index of an array?

A

variable.length - 1

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

What is a function in JavaScript?

A

process or set of actions that can be repeated within your code

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

Describe the parts of a function definition.

A

There is a function keyword, name of the function, parameter list with parentheses, curly brace, code that is running, return function

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

Describe the parts of a function call.

A

function name, parentheses, arguments

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

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

A

Function call –> function keyword is not present for function call
function definition –> includes the code block + function keyword

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

What is the difference between a parameter and an argument?

A

parameter –> placeholder –> prepared to fulfill later
argument –> actual thing to call the function to execute

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

Why are function parameters useful?

A

it allows us to have variants depending on how we run the code. You could get different results with new values.

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

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

A

stops the functions
giveback a value

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

Why do we log things to the console?

A

for debugging, verification to check for data is working

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

What is a method?

A

function stored as an object

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

How is a method different from any other function?

A

method has a dot and a thing you’re calling it from (variable)

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

How do you remove the last element from an array?

A

.pop()

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

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

A

Math.floor() –> it’s always going down

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

How do you generate a random number?

A

Math.random()

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

How do you delete an element from an array?

A

.splice()

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

How do you append an element to an array?

A

.push()

45
Q

How do you break a string up into an array?

A

.split()

46
Q

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

A

No, it does not change the original string. Using console.log to check it

47
Q

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

A

No because it’s situational
we never save our return value - console.log, .pop, .push

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 test a condition, to make choices, to branch to different paths

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 statement –> condition –> conditional code block –> else statement

54
Q

What are the three logical operators?

A

&&, | |, ! (logical Not)

55
Q

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

A

&& or | |

56
Q

What is the purpose of a loop?

A

a tool that allows you to do something repeatedly

57
Q

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

A

It tells us when to stop
the ultimate goal is to see if we need to keep going

58
Q

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

A

It means single repetition

59
Q

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

A

before its iteration of the code block

60
Q

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

A

only once before anything else (before it runs)
before anything

61
Q

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

A

before the code block runs
before each iteration

62
Q

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

A

after each iteration and before the condition

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

64
Q

What does the ++ increment operator do?

A

it allows it to increment by 1, permanently

65
Q

How do you iterate through the keys of an object?

A

use a for…in loop

66
Q

What is JSON?

A

JavaScript Object Notation
being able to store the data in order to transfer through a server and to other devices

text based data that follows the JS syntax
data interchanged format based on JS syntax

67
Q

What are serialization and deserialization?

A

Serialization → process of turning an object in memory into a stream of bytes so you can do stuff such as storing it on disk or send it over the network

spread out memory turned into order of memory to send it over

Deserialization → turning a stream of bytes into an object in memory
taking things out of order

68
Q

Why are serialization and deserialization useful?

A

serialization –> turn to a series of values that are easily savable and transferrable
deserialization –> turn them so it is more accessible

69
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

70
Q

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse()

71
Q

How do you store data in localStorage?

A

.setItem (keyName, Value)

keyName is like a variable - be accurate with what you are storing

72
Q

How do you retrieve data from localStorage?

A

.getItem (keyName)

73
Q

What data type can localStorage save in the browser?

A

strings

74
Q

When does the ‘beforeunload’ event fire on the window object?

A

when the document and its resources are about to be unloaded

75
Q

What is a method?

A

property of an object that contains a function definition
function that is assigned to a property

76
Q

How can you tell the difference between a method definition and a method call?

A

method definition: assign the function definition to the property
method call: call the object. property and its function name

77
Q

Describe method definition syntax (structure).

A

Object literal = {
property: function( ) definition

78
Q

Describe method call syntax (structure).

A

objectName.propertyFunctionName()

79
Q

How is a method different from any other function?

A

need to specify the object name

80
Q

What is the defining characteristic of Object-Oriented Programming?

A

having data (as properties) and behavior (as methods) within the object

81
Q

What are the four “principles” of Object-Oriented Programming?

A

AEIP
Abstraction
Encapsulation
Inheritance
Polymorphism

82
Q

What is “abstraction”?

A

being able to work with complex things in simple ways
simply interaction with the possible complex processes behind the scene

83
Q

What does API stand for?

A

application programming interface

84
Q

What is the purpose of an API?

A

It is a way for two or more computer programs to communicate with each other

85
Q

What is this in JavaScript?

A

it is an implicit parameter, which is available in a function’s code block although it was never included in a function parameter

86
Q

What does it mean to say that this is an “implicit parameter”?

A

it is being implied without explicitly stated

87
Q

How can you tell what the value of this will be for a particular function or method definition?

A

we won’t know

88
Q

How can you tell what the value of this is for a particular function or method call?

A

looking at the objectName that is on the left of the dot notation

89
Q

When is the value of this determined in a function; call time or definition time?

A

call time

90
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance

91
Q

What is a prototype in JavaScript?

A

it’s a source of data or behavior that will get built off of for other things.
object with a shared behavior or data that can be stored in one place but shared in all instances

92
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

it will look at its own prototype that can be used to call each methods

93
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

look at each prototype object
it will go one by one to look for it

94
Q

What does the new operator do?

A
  1. creates a blank object
  2. takes the value of the prototype property off of the function that was created and makes it an operator of the object that was created
  3. the object is being assigned with ‘this’ properly within that function
    allows the object to ‘this’
  4. if the function doesn’t return anything(it never returns), then the object gets returned automatically
95
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

.prototype property

96
Q

What does the instanceof operator do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
the return value is a boolean
syntax: object instanceof constructor

97
Q

What is a “callback” function?

A

A function passed into another function as an argument
which is then invoked inside the outer function to complete some kind of routine or action

98
Q

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout() allows us to do it once

99
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

100
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

zero,

101
Q

What do setTimeout() and setInterval() return?

A

setInterval() & setTimeout() returns –> a timeoutID

102
Q

What does the acronym LIFO mean?

A

Last-In-First-Out

103
Q

What methods are available on a Stack data structure?

A

.pop()
.push()
.peek()
.print()

104
Q

What must you do to access the value at an arbitrary point in a stack (not just the “top”)?

A

You could remove the first index and then return the the new first index if you were to grab the second index of the original dataset.

105
Q

What methods are available on a Queue data structure?

A

dequeue()
enqueue()

106
Q

What is FIFO

A

FIRST-IN-FIRST-OUT

107
Q

What must you do to access the value at an arbitrary point in a queue (not just the “front”)?

A

enqueue() the first value to access the next one up

108
Q

How are linked lists different from an array?

A

Linked lists are sequential access, not random access like an array

109
Q

How would you access an arbitrary node in a linked list (not just the “head”)?

A