JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Variables can hold any data value and can changed anytime

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

How do you declare a variable?

A

You declare using var (keyword) and variable 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

=

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

Letter, dollar sign, and underscore to start and numbers

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

First letter shouldn’t be capitalize and every letter capitalized after is different string value than the non-capitalized string values.

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

To hold values as letters/text and change

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

To hold values as numbers for arithmetic

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 hold values of true or false for decision making

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

Putting a value into something

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

They both represent empty value but null is empty on purpose - it has to be assigned to something while undefined is not assigned a value.

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

Gives us point of reference

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, boolean, number, null, undefined, symbol

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

numeric data type

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

What is string concatenation?

A

Process of joining together two or more 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 and string 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 data type

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 additional data value 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

Object groups a set of variables(properties) and functions(methods) to create a model.

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

What are object properties?

A

Variables that are part of the object

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

Describe object literal notation.

A

{} with whatever properties : method name

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

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

Dot or bracket notations

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

What are arrays used for?

A

Array is used to store list of values and indexed with set order

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

Describe array literal notation.

A

Array literal notation is using [] to list with data separated by commas

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 list with set 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]

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 shows the total number of items 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

[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 statement grouped to perform a specific task and be repeatable

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 is used to create a new function followed by optional name and () then {} and optional 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

Name of function you want to call with parentheses and arguments if needed

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 definition does not allow the code block to be run while function call allows function to be run. Definition requires {} for code block while call requires () for possible argument

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

Why are function parameters useful?

A

Function parameters are useful when replacing values to a function

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

Why do we log things to the console?

A

To check our mistakes in javascript by checking the console output and help debug

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

What is a method?

A

A method is a function which is a property of an object.

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

How is a method different from any other function?

A

function can be called directly while method uses dot notation with object name and method name

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

How do you delete an element from an array?

A

splice() method

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

How do you break a string up into an array?

A

split() method

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

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

A

String method cannot be changed. You check by trying it and look for online source like MDN

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

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

A

a lot

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

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

A

No, it is not necessary when a return is already given

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

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

A

thirty

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

Give 6 examples of comparison operators.

A

=== (strictly equal to), != (is not equal to), >(greater than), !==, >=, <= (less than or equal to)

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

What is the purpose of an if statement?

A

It helps in decision-making

52
Q

Is else required in order to use an if statement?

A

No, else is alternative, but not everything needs alternative

53
Q

Describe the syntax of an if statement.

A

if () {}

54
Q

What are the three logical operators?

A

&& (logical and), || (logical or), ! (logical not)

55
Q

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

A

using logical operator

56
Q

What is the purpose of a loop?

A

Purpose of a loop is to repeat the same code number of times until it is false

57
Q

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

A

to determine to keep going or stop the loop

58
Q

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

A

every time the code block runs

59
Q

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

A

beginning of the loop and each iteration

60
Q

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

A

at the start of the loop once

61
Q

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

A

before each iteration

62
Q

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

A

after 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

64
Q

What does the ++ increment operator do?

A

increases the value of the variable

65
Q

How do you iterate through the keys of an object?

A

for in loops

66
Q

What is the difference between a parameter and an argument?

A

look it up

67
Q

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

A

look it up

68
Q

What is the event.target?

A

stores where the object originated from

69
Q

What is the affect of setting an element to display: none?

A

The element disappears and no longer take space on the web page

70
Q

What does the element.matches()

A

a

71
Q

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

A

getAttribute()

72
Q

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

A

verify the values of the variables, logging the values of the attributes

73
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

we’d have to add an event listener to every element

74
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

write a conditional instead for each view

75
Q

What is JSON?

A

JSON stands for JavaScript Object Notation and is a format to store and transport data. Data exchange format that is a string.

76
Q

What are serialization and deserialization?

A

Serialization is the process of of turning an object in memory into a stream of bytes so you can do store on hardware or send it over the network. Deserialization is the opposite by turning a stream of bytes into an object in memory.

77
Q

Why are serialization and deserialization useful?

A

They are useful in exchanging data: you can send objects over a network and it can be parsed by the reciever

78
Q

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

A

JSON.stringify - converts a JavaScript object or value to a JSON string

79
Q

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

A

JSON.parse - data becomes a JavaScript object

80
Q

How do you store data in localStorage?

A

Storage.setItem() with key: string; value: any data type

81
Q

How do you retrieve data from localStorage?

A

Storage.getItem() with key as argument

82
Q

What data type can localStorage save in the browser?

A

string

83
Q

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

A

It is fired when the window, document, and its resources are about to be unloaded.

84
Q

What is a method?

A
A method is a function which is a property of an object
function stored in a property
85
Q

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

A

property: function() for definition

object. method()

86
Q

Describe method definition syntax (structure).

A

property: function() for definition

87
Q

Describe method call syntax (structure).

A

object.method()

88
Q

What is the defining characteristic of Object-Oriented Programming?

A

OOP allows you to pair data and behavior

89
Q

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

A

Encapsulation, Abstraction, Inheritance, and Polymorphism

90
Q

What is “abstraction”?

A

Working with complex things in simple ways by focusing on details of greater importance.

91
Q

What does API stand for?

A

Application Programming Interface

92
Q

What is the purpose of an API?

A

A set of functions that allows applications to access data and interact with external software components, operating systems, or microservices. An API delivers a user response to a system and sends the system’s response back to a user.

93
Q

How is a method different from any other function?

A

Methods are functions attached to objects

94
Q

What is “this” in JavaScript?

A

It’s the object that is acting on

95
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

96
Q

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

A

call time

97
Q

What does “this” refer to in the following code snippet?

A

Nothing but act as a placeholder

98
Q

Given the above character object, what is the result of the following code snippet? Why?

A

Mario

99
Q

Given the above character object, what is the result of the following code snippet? Why?

A

undefined because we’re calling window.hello() and does not have property

100
Q

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

A

You can’t know

101
Q

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

A

left of the dot

102
Q

What kind of inheritance does the JavaScript programming language use?

A

prototypal inheritance

103
Q

What is a prototype in JavaScript?

A

Mechanism that allows JavaScript objects to inherit features from one another

104
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

setPrototypeOf()

105
Q

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

A

proto

106
Q

What does the new operator do?

A

The new operator 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.

107
Q

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

A

prototype property

108
Q

What does the instanceof operator do?

A

to test if an object is of a given type

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

110
Q

Besides adding an event lister 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()

111
Q

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

A

setInterval()

112
Q

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

A

0

113
Q

What do setTimeout() and setInterval() return?

A

a timeoutID which is a positive integer identifying the timer created as a result of calling the method. IntervalID which will be an integer value

114
Q

What is AJAX?

A

AJAX allows you to make asynchronous calls to a web server - this allows client browser to avoid waiting for all data to arrive before allowing the user to act once more.
The main purpose of AJAX is to increase speed, performance, usability of a web application.

115
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

116
Q

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

A

XMLHttpRequest

117
Q

What event is fired by XMLHttpRequest objects when they are finished loading?

A

load event

118
Q

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

A

they share the same prototype property (event.target.prototype)

119
Q

What is the JavaScript Event Loop?

A

event loop checks if the stack is empty. it takes the first item on the queue and pushes to the stack. Checks to see if JavaScript is not busy

120
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

blocking would be synchronous and blocking is code that is currently blocking the call stack and non-blocking would be non-synchronous

121
Q

What is Array.prototype.filter useful for?

A

When you only want some of the data

122
Q

What is Array.prototype.map useful for?

A

t is useful when you want to update or change the values inside the array list

123
Q

What is Array.prototype.reduce useful for?

A

It is useful when we want single output from array

124
Q

What must the return value of myFunction be if the following expression is possible? myFunction()();

A

myFunction returns another function and that returned function is what’s getting called -first () invokes first function and second () invokes second function

125
Q
What does this code do?  
const wrap = value => () => value;
A

the value of inner function

126
Q

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

A

When it is defined because when function is declared by code block the scope is determined

127
Q

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

A

lexical environment: closure