JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store pieces of 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

With the var keyword (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

Initialize a variable by assigning it to a value with 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

Dollar signs, underscores and 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

Variable names can be the same word but with different casings. Ex) var pRicE; and var Price; both work

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

For storing and manipulating 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

Data type to represent and manipulate number values

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

a True or false value for all javascript comparison and conditions

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 between the variable and data

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

Assign the variable to a new value; no declaration

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

What is the difference betweennullandundefined?

A
  • Undefined is not assigned

- Null is an error,

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 confirm what type of data type you are working with, or what value is inside the variable

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

Depends. Going from left to right of the expression. It’ll work out the math operations then concatenate if a string is there.

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

What is string concatenation?

A

Adding two operands together with an addition operator

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

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

A

A boolean value

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

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

A

Adds the value on the right of the variable to the left of the operator. Then assigns the result to the variable

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

What are objects used for?

A

Allow a collection of data for a specific theme. Data organization

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

What are object properties?

A

Variable within an object literal

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

Describe object literal notation

A

Key value pairs within curly braces being assigned to a variable name

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

How do you remove a property from an object?

A

Using the “delete” operator

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

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

A

Using dot notation or you can use bracket notation

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

What are arrays used for?

A

To list out multiple values of similar data

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

Describe array literal notation

A

Square brackets with data divided by commas being assigned to a variable declaration

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

How are arrays different from “plain” objects

A

Key numbered index, 0 based

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

What is the length property of an array?

A

Numbers of entries in an array

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

How do you calculate the last index of an array?

A

Array[Array.length - 1]

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

What is a function in JavaScript

A

Set of reusable code saved under a special type of object to be invoked(called);

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

Describe parts of a function definition

A

Curly braces around a code block being assigned to a function definition with parentheses
1. function 2. name(optional) 3. parameters(optional) 4. codeblock 5. return

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

Describe the parts of a function call

A

Invoke the name of the function with arguments within the parentheses

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

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

A

Seeing a code block means its a function definition. Then also telling what is an argument and a parameter.

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

What is the difference between aparameterand anargument?

A

A parameter is before calling the function

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

Why are functionparametersuseful?

A

Pass additional information into the function, couldn’t have dynamic data without it

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

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

A

Produce a value where the function is called, instead of having undefined.

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

Can code execute after the return keyword?

A

No. It finishes after return is ran.

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

To keep track of any updates to variables

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

What is a method

A

A function property within 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 is a function of an object.

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

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, .pop, or shift() all alter the array

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 or .unshift()

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

How do you break a string up into an array?

A

.split(“ “). Space would divide words

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

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

A

No, because primary data types are immutable. Console.log

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

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

A

30

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

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

A

No, because methods like splice();

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

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

A

36

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

Give 6 examples of comparison operators.

A

greater than, less than, greater than or equal to, less than or equal to, strict equality, not comparison

52
Q

What data type do comparison expressions evaluate to?

A

Booleans

53
Q

What is the purpose of anifstatement?

A

Executes a statement if a specific condition is true, another statement can be executed if false

54
Q

Iselserequired in order to use anifstatement?

A

No

55
Q

Describe the syntax (structure) of anifstatement.

A

if keyword, condition expression, brace for code block, statement1

56
Q

What are the three logical operators?

A

And, or, not, || = double pipe ! = bang

57
Q

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

A

Using a logical operator between conditional

58
Q

What is the purpose of loops?

A

To perform repeated tasks based on how many times the condition remains true.

59
Q

What is the purpose of aconditionexpression in a loop?

A

Tells the loop when to run as long as the result remains true

60
Q

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

A

Every instance the code between the code block runs

61
Q

Whendoes theconditionexpression of awhileloop get evaluated?

A

Whendoes theconditionexpression of awhileloop get evaluated?

62
Q

Whendoes theinitializationexpression of aforloop get evaluated?

A

Executed ONCE at the very start of the loop.

63
Q

Whendoes theconditionexpression of aforloop get evaluated?

A

Right before each iteration.

64
Q

Whendoes thefinalexpression of aforloop get evaluated?

A

Happens at the end of each loop. Usually to increment or decrement a counter.

65
Q

Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?

A

Break.

-Rare usage. But can be used to exit a loop when found a value.

66
Q

What does the++increment operator do?

A

Adds one to the operand. Depending on the position of it.

67
Q

How do you iterate through the keys of an object?

A

Using for…in to iterate over properties of an object.

68
Q

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

A

‘focus’

69
Q

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

A

‘blur’

70
Q

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

A

‘input’

71
Q

What event is fired when a user clicks the”submit”button within a?

A

‘submit’

72
Q

What does theevent.preventDefault()method do?

A

‘Prevents the page from automatically reloading the page’

Without it, if the form is wrong (even if method and get link to same page), page keeps reloading.

73
Q

Where should event.preventDefault() go?

A

At the beginning of the function.

74
Q

What does submitting a form withoutevent.preventDefault()do?

A

Reloads the page

75
Q

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

A

.elements

76
Q

What property of form a control object gets and sets its value?

A

value

77
Q

What is JSON?

A

text-based data string format. Replicating javascript object syntax

78
Q

What are serialization and deserialization?

A
  • Serialization: Converting unordered data like an object to storable bits, which is usually a string
  • Deserialization is the reverse. Turning that string of text into an object in memory.
79
Q

Why are serialization and deserialization useful?

A
  • Allows saving the state of an object and recreating it as needed.
  • Allows transferring data efficiently
80
Q

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

A

Var something = JSON.stringify([{}]

81
Q

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

A
var obj = JSON.parse('[{"id:":"31023"}]');
-Notice the double quotes.
82
Q

What is the affect of setting an element todisplay: none?

A

That affected element disappears on the web page, and it won’t interfere with the document flow

83
Q

What does theelement.matches()method take as an argument and what does it return?

A

Returns a boolean value indicated if the element is matched with the specific CSS selector

84
Q

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

A

getAttribute method of the element

85
Q

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

A

Make a new event listener for every element

86
Q

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

A

Massive conditional block for every

87
Q

How to you store data inlocalStorage?

A
  • With storage.setItem(key,value);

- .setItem method,

88
Q

How to you retrieve data fromlocalStorage?

A

getItem();

89
Q

What data type canlocalStoragesave in the browser?

A

string data

90
Q

When does the’beforeunload’event fire on thewindowobject?

A

When the window,document and its resources are about to be unloaded

91
Q

What is amethod?

A

Methods are functions that are stored in object properties.

92
Q

How can you tell the difference between a methoddefinitionand a methodcall?

A
  • Method definition goes within the object with the code block
  • Method call is outside the object and is called as a property(method) on the object.
    • Has the dot.
93
Q

Describe methoddefinitionsyntax (structure).

A
  • Create a new property inside our object
  • Property Name : function(){ code block}
  • You can assign the property with the value function outside the object as well.
94
Q

Describe methodcallsyntax (structure).

A

Property method of the object being calling with arguments;

95
Q

How is a method different from any other function?

A

Unlike other functions, methods only exist within this object, so you must call it along the object.

96
Q

What is thedefining characteristicof Object-Oriented Programming?

A

Working with objects, which contain both data(as properties) and behavior(as methods)

97
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

98
Q

What is “abstraction”?

A

Being able to work complex things in simple ways

99
Q

What does API stand for?

A

Application Programming Interface

100
Q

What is the purpose of an API?

A
  • Give programmers a way to interact with a system in a simplified, consistent fashion.
  • Specifically abstraction
101
Q

Procedural programming

A

Loosely means declared variables to hold the state of application and defined functions to update those variables.
- Variables and functions were separate

102
Q

What is a “callback” function?

A
  • Function being passed around as a value.

- which is then invoked inside the outer function to complete some kind of routine or action.

103
Q

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

A

setTimeout & setInterval

104
Q

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

A

setInterval(function, seconds);

105
Q

What is the default time delay if you omit thedelayparameter fromsetTimeout()orsetInterval()?

A

0ms. The value of omitting it, it runs after the functions without setInterval and setTimeout.

106
Q

What dosetTimeout()andsetInterval()return?

A
  • It returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval()
  • 1000 = id of 1.
  • Interval and Timeout share incrementing IDs
107
Q

What isthisin JavaScript?

A

An implicit parameter of all JS functions.

This, refers to the object it belongs to. Alone, this refers to the global object.

108
Q

What does it mean to say thatthisis an “implicit parameter”?

A

Available in a functions code block even though it was never included in the functions parameters list or declared with var.

109
Q

Whenis the value ofthisdetermined in a function;call timeordefinition time?

A

When the function is called.

110
Q

How can you tell what the value ofthisis for a particular function or methodcall?

A

this is only a value when function is being invoked. this is the object to the left of the dom.

111
Q

What is the goal of Inheritance?

A

To move properties and methods we’d like to reuse into a prototype object and tell other objects to simply delegate to that prototype object.

112
Q

Why is it possible to call doggo.speak() or kitteh.speak() even though they don’t have those methods defined on them?

A

These methods are located in the prototype object

113
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal Inheritance

114
Q

What is a prototype in JavaScript?

A

Object with set properties, and we can add our own methods on it

115
Q

How do we set the prototype of a specified object to another object?

A

Object.setPrototypeOf(obj, prototype)

116
Q

How do we get the prototype of a specified object?

A

Object.getProtypeOf(obj);

117
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

Every object has a set property list of methods

118
Q

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

A

In the object [[prototype]] property

119
Q

What does thenewoperator do?

A

4 Step:

  1. Create a blank JavaScript Object
  2. Adds a property to the new Object (__proto__) that links to the constructor function’s prototype object
  3. Binds the newly creating object instance as the this context
  4. Returns this if the function doesn’t return an object
120
Q

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

A

.Prototype property

121
Q

What does theinstanceofoperator do?

A

Tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
- Returns a boolean value.

122
Q

Is there a return from the new instance property

A

Yes, and you don’t have to specifically return it.

123
Q

What is AJAX?

A

AJAX is a technique for creating fast and dynamic web pages.

124
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML.

125
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest()

126
Q

What event is fired byXMLHttpRequestobjects when they are finished loading the data from the server?

A

‘load’

127
Q

AnXMLHttpRequestobject has anaddEventListener()method just like DOM elements. How is it possible that they both share this functionality?

A
  • XML object and DOM elements are instaces of Object

- Share object in their prototypal chain