JavaScript Flashcards

1
Q

What is the purpose of variables?

A

stores data value that can be changed and used later on

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 var keyword.

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 keyword, variable name, assignment operator, and value.

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

variable names cannot contain any spaces. Must start with a letter, underscore, or dollar sign. names can only contain letters, numbers, underscores, or dollar signs. names are case sensitive.

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

means any identifier must be typed with a consistent capitalization of numbers.

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

What is the difference between null and undefined?

A

null is representation of no value, undefined means a variable has been declared but not yet has been assigned a value.

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

so that you know what is being logged.

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

Give five examples of JavaScript primitives.

A

strings, numbers, null, undefined, boolean

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

What data type is returned by an arithmetic operation?

A

numbers

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

What is string concatenation?

A

joining string together.

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

What purpose(s) does the + plus operator serve in JavaScript?

A

for concatenation and adding numeric values together

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

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

A

boolean value

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

What are objects used for?

A

objects group together a set of variable and functions to create a model of something.

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

What are object properties?

A

a variable that is part of an object.

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

Describe object literal notation.

A

var keyword, variable name, assignment operator, key value pairs.

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

How do you remove a property from an object?

A

use delete keyword followed by the object name and property name.

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

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

A

object name, dot notation, followed by property name, assignment operator and property value. object name, square bracket, property name in string assignment operator, and property value.

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

What are arrays used for?

A

a list or set of values that are related to each other. Making lists of related of the exact same type.

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

What is the length property of an array?

A

gives the number of items in array.

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

Describe array literal notation.

A

var keyword, variable name, assignment operator, square bracket, array values.

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

How are arrays different from “plain” objects?

A

arrays keys are index, object keys are properties.

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

What is a function in JavaScript?

A

a set of statements that performs a task or calculates a value and can be reused throughout a program

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

Describe the parts of a function definition.

A

function keyword, optional function name, parameter with optional values, followed by code block for the function. optional return statement.

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

Describe the parts of a function call.

A

function name, with optional arguments.

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

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

A

function call does not have the function keyword. function call does not have a code block to execute.

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

What is the difference between a parameter and an argument?

A

Parameters are variables listed as a part of the function definition. Arguments are values passed to the function when it is invoked.

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

Why are function parameters useful?

A

You can think of a parameter as a placeholder. It is basically a variable whose value is not known until we call the function and pass an argument. When the function’s code block is run, the parameter will be holding the value of the argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
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 in our program. 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
32
Q

Why do we log things to the console?

A

debugging tool used to check what your output would be.

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

How is a method different from any other function?

A

methods are always related to objects, functions are not. methods are built in, functions are not. when using a method, there will always be a dot before the method and a parenthesis after.

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

How do you remove the last element from an array?

A

pop method on the array

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

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

A

using floor method of math object.

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

How do you generate a random number?

A

using random method of math object.

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

How do you delete an element from an array?

A

using pop method on the array to delete last item, or using shift method on the array to delete first item. You can also use splice method on the array and specify the beginning and number of items to manually delete items in array

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

How do you append an element to an array?

A

using push method on the array

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

How do you break a string up into an array?

A

using the split method on the string.

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

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

A

no, you can console log the original string to see if anything changed.

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

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

A

about 50.

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

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

A

no because when using methods, the return value may not be needed.

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

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

A

around 35

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

Give 6 examples of comparison operators.

A

strictly equals, less than, less than or equal to, greater than, greater than or equal to, not strictly equals.

47
Q

What data type do comparison expressions evaluate to?

A

boolean

48
Q

What is the purpose of an if statement?

A

a conditional statement in which if met, then your code executes one or more statements, else your code does something different. Decision making tool.

49
Q

Is else required in order to use an if statement?

A

no

50
Q

Describe the syntax (structure) of an if statement.

A

if keyword, condition, and code block for if statement.

51
Q

What are the three logical operators?

A

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

52
Q

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

A

using logical and (&&) or logical or (| |)

53
Q

What is the purpose of a loop?

A

loops will run a set of code block until the condition evaluates to false. Used for repetition.

54
Q

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

A

the loop runs until the counter reaches a specified number.

55
Q

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

A

An expression evaluated before each pass through the loop. If this condition evaluates to true, statement is executed. When condition evaluates to false, execution continues with the statement after the while loop. Tells when to start and end.

56
Q

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

A

when the loop executes one round of the condition

57
Q

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

A

once before the loop iteration begins, never again.

58
Q

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

A

An expression to be evaluated before each loop iteration. right after the final expression right before the code block.

59
Q

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

A

An expression to be evaluated at the end of each loop iteration.

60
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

use break statements to terminate a loop.

61
Q

What does the ++ increment operator do?

A

adds one to its operand and returns a value

62
Q

How do you iterate through the keys of an object?

A

using for in loop

63
Q

What is the event.target?

A

show the element where an event happened.

64
Q

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

A

hides that element from viewport

65
Q

What does the element.matches method take as an argument and what does it return?

A

css selector as a string as an argument and returns a boolean value of whether the elements match.

66
Q

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

A

Object.getAttribute method

67
Q

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

A

every single step.

68
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

you would have to use add event listener on every new tabs. this is not scalable.

69
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

you would have huge condition block for every view. it is not scalable.

70
Q

What is JSON?

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. Data exchange format.

71
Q

What are serialization and deserialization?

A

Converting a string to a native object is called deserialization, while converting a native object to a string so it can be transmitted across the network is called serialization.

72
Q

Why are serialization and deserialization useful?

A

useful when you want to transmit data across a network.

73
Q

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

A

JSON.stringify

74
Q

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

A

JSON.parse

75
Q

How to you store data in localStorage?

A

setItem method on localStorage object with arguments of storage name in string and JSON variable

76
Q

How do you retrieve data from localStorage?

A

getItem method on localStorage object with argument of storage name in string format.

77
Q

What data type can localStorage save in the browser?

A

string

78
Q

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

A

when the window, the document and its resources are about to be unloaded. before you close, refresh web page.

79
Q

What is a method?

A

a set of procedures to follow in an object. A function which is a property of an object.

80
Q

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

A

method calls will always have an object and dot before the methods name followed by parenthesis. method definition is assigning function definition to object. method call will always have parenthesis.

81
Q

Describe method definition syntax (structure).

A

inside an object literal variable, there is a key value pair. the key is the name of the method, and the value will be a function definition defining the method.

82
Q

Describe method call syntax (structure).

A

object name, dot notation and method name followed by optional arguments.

83
Q

How is a method different from any other function?

A

methods always related to objects, functions aren’t. functions can be called without objects.

84
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

85
Q

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

A

abstraction, encapsulation, inheritance, polymorphism.

86
Q

What is “abstraction”?

A

simplifying complex steps of procedures into one generalized step so that it is more accessible to people who understand the steps. (ie. light switch).

87
Q

What does API stand for?

A

application programming interface

88
Q

What is the purpose of an API?

A

allows applications to communicate with each other. prewritten tools that developers can use

89
Q

what is “this” in JavaScript?

A

the object that a property belongs to. object you are currently working with.

90
Q

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

A

parameter that is available in a function’s code block even though it was never included in the function’s parameter list or declared with var. Given to the function even though it is not listed as parameter.

91
Q

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

A

call time. This does not have a value until function is called.

92
Q

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

A

you cant, value of this is defined when function or method is being called.

93
Q

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

A

Find where the function is called and look for an object to the left of the dot. If there is no value to the left of the dot, the value of this is window.

94
Q

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

A

the object character. nothing, because greet has not been invoked.

95
Q

Given the code above “character” object, what is the result of the following code snippet and why?

A

It’s a me, Mario! Because we are calling the method of greet, which will log the message.

96
Q

Given the code above “character” object, what is the result of the following code snippet and why?

A

undefined, because greet is a method, and character.greet will give us the function definition not the functionality of the function definition.

97
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance.

98
Q

What is a prototype in JavaScript?

A

a JavaScript object that holds properties and methods that can later be used when needed. Object that other objects can build off of.

99
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

grabbing it from prototypes.

100
Q

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

A

prototypes.

101
Q

What does the new operator do?

A

lets you create an instance of a user-defined object type or of one of the built-in object types that has a constructor function. constructor functions should never return anything.

102
Q

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

A

prototype

103
Q

What does the instanceof method do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. check left of instanceof to see if it is part of the prototypal chain on the right.

104
Q

What is a “callback” function?

A

a function passed to another function as argument.

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

106
Q

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

A

setInterval()

107
Q

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

A

immediate

108
Q

What do setTimeout() and setInterval() return?

A

a numeric, non-zero value which identifies the timer created by the call

109
Q

What is AJAX?

A

AJAX allows you to request data from a server and load it without having to refresh the entire page.

110
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

111
Q

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

A

XMLHttpRequest

112
Q

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

A

load

113
Q

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

A

they both share a prototype. prototype of element is node