JavaScript Flashcards

1
Q

what is the purpose of variables?

A

store data for reuse

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

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

var x = ‘string’;

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, $, _

however must start with letter, $, or _.

must not use - or .

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

the slightest capitalization difference for the same word will count as different variables

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

what is the purpose of string?

A

used when working with any kind of 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

for tasks that involve counting or calculating sums

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

what is the purpose of boolean?

A

helpful when determining which part of a script should run/ acts as an on or off switch

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 operator

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

use the variable name, the equals sign, and the 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 represents a reference that points to a nonexistent or invalid object or address

undefined is a value assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments

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

easier to keep track of console output for yourself and others

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, undefined, null

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

placing string together to form a single output of string

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 JS?

A

concatenation and addition

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 value of the right operand to a variable and assigns the result to the variable

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

what are objects used for?

A

objects group together a set of variables and functions to create a model of something you would recognize from the real world

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

what are object properties?

A

exclusive variables - another way to store data

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

describe object literal notation

A

assigning the object properties within { }

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

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

when you are working with a list or a set of values that are related to each other

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

describe array literal notation

A

var colors = [ ] ;

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 use indexes to keep track of items

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

tells how many items are in the 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

array.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

set of statements that perform a task

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

function keyword, optional name, parameters, code block, return statement, {}

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, 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 - actually using the function

function definition - creating the code to run

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

parameters are variables that doesn’t have a value yet

arguments are the user values

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

why are function parameters useful?

A

used as placeholders for when the function is called

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

causes the function to produce a value we can use

prevents any more code in the function’s code block from being run

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

during development, check if output matches what you are expecting

debugging

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

what is a method?

A

function which is a property of an object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
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
40
Q

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

A

Math.floor()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
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
42
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
43
Q

how do you append an element to an array?

A

.push()

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

how do you break a string up into an array?

A

.split()

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

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

A

they return a new string

check with MDN - documentation or try yourself on console log

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

roughly how many string methods are there according to the MDN web docs?

A

~35 remember to check MDN

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

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

A

no, sometimes function/methods do not need to return a value

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

roughly how many array methods are there according to the MDN web docs?

A

~30 remember to check MDN

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

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

A

MDN

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

give 6 examples of comparison operators

A
===
!==
>=
<=
>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

what data type do comparison expressions evaluate to?

A

boolean

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

what is the purpose of an if statement?

A

checks if a condition is true or false to execute code

53
Q

is else required in order to use an if statement?

A

no, can be used to just check condition

54
Q

describe the syntax(structure) of an if statement

A

if conditional statement, ( condition ), { } if code block

55
Q

what are the three logical operators

A

&& logical and

|| logical or

! logical not

56
Q

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

A

logical and, logical or

57
Q

what is the purpose of a loop?

A

loops check a condition; if it returns true, a code block will run. condition checked again and will repeat if still true. repeats until condition returns false

58
Q

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

A

have the loop continue to run until the counter reaches a specified number

59
Q

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

A

iteration refers to the process in which the content of loop is executed once

60
Q

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

A

evaluated before each code block

61
Q

when does the initialization expression of a for loop get evaluated

A

evaluated before the loop begins

62
Q

when does the condition expression of a for loop get evaluated

A

after initialization, before code block runs

63
Q

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

A

evaluated at the end of each loop iteration. this occurs before the next evaluation of a condition

64
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

65
Q

what does the ++ increment operator do?

A

adds one

66
Q

how do you iterate through the keys of an object?

A

for/in loop

67
Q

what event is fired when a user places their cursor in a form control?

A

focus

68
Q

what event is fired when a user’s cursor leaves a form control?

A

blur

69
Q

what event is fired as a user changes the value of a form control?

A

input

70
Q

what event is fired when a user clicks the “submit” button within a form?

A

submit

71
Q

what does the event.preventdefault() method do?

A

tells the user agent that if the vent does not get explicitly handled, its default action should not be taken as it normally would be

72
Q

what does submitting a form without event.preventDefault() do?

A

reloads the page

73
Q

what property of a form element object contains all of the form’s controls

A

elements

74
Q

what property of form a control object gets and sets its value

A

.value property

75
Q

what is one risk of writing a lot of code without checking to see if it works so far?

A

there could be some typo or miscalculated result that messes with the whole code

76
Q

what is an advantage of having your console open when writing a javascript program?

A

you can test things out and prevent possible bugs

77
Q

what is the event.target?

A

reference to the object onto which the event fired

78
Q

what is the effect of setting an element to display: none?

A

element will not be visible

79
Q

what does the element.matches() method take as an arugment and what does it return?

A

selectorString as argument

returns boolean

80
Q

how can you retrieve the value of an element’s attribute?

A

.getAttribute() method

81
Q

at what steps of the solution would it be helpful to log things to the console?

A

whenever you are using a method, property, or calculation

82
Q

if you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JS code be writen instead?

A

need to add event listeners to each new node

83
Q

if you didn’t use a loop to conditionally show or hide the views in the page, how would your JS code be written instead?

A

you would have to get the variable for each index and compare for every single one

84
Q

what is JSON?

A

text-based data format following JS object syntax

85
Q

what are serialization and deserialization?

A

serialization - process of converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage

deserialization - fetch a stream of bytes from network or persistence storage and convert it back to the Object with the same state

86
Q

why are serialization and deserialization useful?

A

compress/decompress data to keep accurate data when sharing with others

87
Q

how do you serialize a data structure into a JSON string using Javascript?

A

JSON.stringify() method

88
Q

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

A

JSON.parse() method

89
Q

how do you store data in localStorage?

A

.setItem() method

90
Q

how do you retrieve data from localStorage?

A

.getItem() method

91
Q

what data type can localStorage save in the browser?

A

string

92
Q

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

A

fired when the window, the document, and its resources are about to be unloaded (when user leaves/navigates away from the page

93
Q

what is a method?

A

function which is a property of an object

94
Q

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

A

method definition is where the method is built with code block

method call is when the method definition is being used

95
Q

describe method definition syntax (structure)

A

variable object declration followed by property name and function() with code block

96
Q

describe method call syntax(structure)

A

method.function();

97
Q

how is a method different from any other function?

A

a method is a function, which is a property of an object. use dot notation/bracket notation to access

98
Q

what is the defining characteristic of object-oriented programming?

A

objects can contain both data (as properties) and behavior (as methods)

99
Q

what are the four “principles” of object-oriented programming

A

abstraction
encapsulation
inheritance
polymorphism

100
Q

what is abstraction?

A

the process of removing physical, spacial, or temporal details or attributes in the study of objects or system to focus attention on details of greater importance; similiar in nature to the process of generalization

ex; flicking the lights is more than just turning a switch. there are many micro events that occur, but all you need to know is that you need to flip the switch to turn on/off the lights

101
Q

what does API stand for?

A

application programming interface

102
Q

what is the purpose of an API?

A

it defines interactions between multiple software intermediaries. it defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conversations to follow, etc.

103
Q

what is this in JS?

A

the object

a property of an execution context(global, function, or eval) that, in non-strict mode is always a reference to an object and in strict mode can be any value

104
Q

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

A

it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var

105
Q

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

A

call time

106
Q

what does this refer to in the following code snippet?

var character = {
   firstName: 'Mario',
   greet: function () {
      var message = 'It\'s-a-me, ' + this.firstName + '!';
   console.log(message);
   }
};
A

we don’t know yet as this is the definition time

107
Q

given the above character object, what is the result of the following code snippet? why?

character.greet();

A

It’s a me, Mario!

greet is a function that will return a message

108
Q

given the character object, what is the result of the following code snippet? why?

var hello = character.greet;

A

hello();

it’s a me, undefined

because this is being used on the window object which doesn’t have a firstName property defined

109
Q

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

A

not in strict mode, this will default to the global object, which is a window in a browser

in strict mode, if the value of this is not set when entering an execution context, it remains as undefined

110
Q

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

A

the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method)

if there is no value to the left of the dot when the function is called, then by default, this will be the global window object

if you cannot see the function being called, then you do not know what the value of this will be

111
Q

what kind of inheritance does the JS programming language use?

A

prototype-based inheritance

a style of object-oriented programming in which behavior reuse (known as inheritance) is performed via a process of reusing existing objects that serve as prototypes

112
Q

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

A

prototype chain

113
Q

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

A

prototype object, then to the object’s

114
Q

what does the new operator do?

A

lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function

  • creates a blank, plain JS object
  • links the newly created object to another object by setting the other object as its parent prototype
  • passes the newly created object from step 1 as this context
  • returns this if the function doesn’t return an object
115
Q

what property of JS functions can store shared behavior for instances created with new?

A

prototype property

116
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. return value is a boolean value

117
Q

what is a callback function?

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

118
Q

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

A

setTimeout() method

119
Q

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

A

setInterval() method

120
Q

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

A

value of 0 is used, meaning execute “immediately”, or more accurately, the next event cycle

121
Q

what do setTimeout() and setInterval() return?

A

setTimeout() return is a positive integer value which identifies the timer created by the call to setTimeout()

setInterval() return is a numeric, non-zero value which identifies the timer created by the call to setInterval()

122
Q

what is AJAX?

A

a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequeseet

123
Q

what does the AJAX acronym stand for?

A

asynchronous Javascript and XML

124
Q

what event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

load

125
Q

an XMLHttpRequest object has an addEventListener() method just like DOM elements. how is it possible that they both share this functionality?

A

shares prototype

126
Q

what is Array.prototype.filter useful for?

A

creates a new array with all elements that pass the test implemented by the provided function

127
Q

what is Array.prototype.map useful for?

A

it creates a new array populated with results of calling a provided function on every element in the calling array

128
Q

what is Array.prototype.reduce useful for?

A

when you want to reduce each element of an array to a single output value