JavaScript Flashcards

1
Q

What is the purpose of variables?

A

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

Variable keyword followed by the 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

Variable name followed by an assignment operator followed by a variable 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

letters, numbers, dollar sign, or an underscore. Cannot use dash or a period in a variable name. Cannot use reserved words like var. Cannot start with 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

variables, functions, and any other identifiers must be typed with consistent capitalization of letters.

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

holding data that can be represented in text form. To save a series of characters.

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 represent and manipulate numbers. Represent numeric value. Math, a measurement.

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

datatype that returns either true or false. To make decisions. Allow you to tell the computer do or don’t do.

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. Putting a value to 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

variable name assignment operator and 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

undefined is a variable thats not assigned to anything. null is when purposely assigned a value of nothing until give value later.

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 label value to know what value belongs to which 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

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

joining strings together. Combination of two or more string values.

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

adds one value to another. Adding number values 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

adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.

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. Allows us to store data together. Create collection of stuff.

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

What are object properties?

A

Individual data stored in object.

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

Describe object literal notation.

A

the object is the curly braces and their contents. The object is stored in a variable. Separate each property from its value using a colon. Separate each property and method with a comma.

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

to delete a property, use the 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
23
Q

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

A

using the dot notation or the square brace.

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

What are arrays used for?

A

when 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

use var keyword followed by the name of array. Values are assigned to the array inside a pair of square brackets, and each value 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

plain objects have property value pair, arrays just have values.

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 thelengthproperty of an array?

A

property to find out how many items 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

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

Functions allow you to package up code for use later in your program.
Special type of object that can be called.
Set of reusable code that can be used in the future.

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

the function keyword, an optional name, zero or more parameters, a code block, an 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

the name of the function, parenthesis with optional parameters.

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 functioncalland a functiondefinition?

A

the function keyword is only for definition.
Function call will have arguments. Definition always features a code block that needs to be executed.
Function call will not have curly braces.

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

What is the difference between aparameterand anargument?

A

functions are called with () parentheses and passed zero or more arguments.
Parameter is for function definition.
Argument is for calling functions with specific values.

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

why are function parameters useful?

A

passes on additional information to a function. Can make functions usable and data more dynamic.

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.

Exits the function; no code after the return statement is executed.

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 check the console output to see if your code is working correctly.

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

What is a method?

A

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 is a method different from any other function?

A

Method is a function on an object. A function can be called directly by it name. A method consists of a code that can be called by the name of its object and its method name using dot notation or square bracket notation.

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

using the pop method on the nave of the variable.

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

using floor method of the math object with optional arguments.

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

using the random method on the math object and that expression being argument of the floor method of the math object.

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

using the splice method.

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

using push and unshift methods.

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

using split method

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. you can try running string methods on variable and then console log the original variable to see if it is changed.

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

about 50. There are a lot because strings are important.

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. example: splice. Most built in methods will not need the return value of function.
There are situations where you need to get rid of the data.

49
Q

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

A

about 30.

50
Q

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

A

MDN. Always include the name of the language.

51
Q

Give 6 examples of comparison operators.

A

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

52
Q

What data type do comparison expressions evaluate to?

A

boolean

53
Q

What is the purpose of anifstatement?

A

if statement evaluates (or checks) a condition. If the condition evaluates to true, any statements in the subsequent code block are executed.

54
Q

Is else required in order to use an if statement?

A

no. We don’t always have to do something is condition comes up true.

55
Q

Describe the syntax (structure) of anifstatement.

A

keyword if, condition, opening brace, inside the braces, we have a code to execute if value is true.

56
Q

What are the three logical operators?

A

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

57
Q

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

A

using logical operators.

58
Q

What is the purpose of a loop?

A

To repeat code until condition returns false.

59
Q

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

A

the loop will run until the condition is false.

60
Q

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

A

single time a code blocks runs for a loop.

61
Q

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

A

condition is checked before each iteration.

62
Q

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

A

before the loop begins.

63
Q

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

A

right after the initialization and before each iteration to check and see if it can continue.

64
Q

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

A

at the end of each loop iteration.

65
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 statement.

66
Q

What does the ++ increment operator do?

A

adds one to its operand and returns a value

67
Q

How do you iterate through the keys of an object?

A

using for in loop

68
Q

What are the four components of “the Cascade”.

A

Source Order, Inheritance, Specificity, !important.

69
Q

What does the term “source order” mean with respect to CSS?

A

the order that your CSS rules are written in your stylesheet.

70
Q

How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule

A

Not all properties are inheritable. Do not force properties to become inheritable. Just use the default.

71
Q

List the three selector types in order of increasing specificity.

A
  • type selectors, class selectors, id selectors.
72
Q

Why is using !important considered bad practice?

A

because it makes debugging more difficult by breaking the natural cascading in your stylesheets.

73
Q

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

A

hides that element from viewport and removed from document flow.

74
Q

what does matches method take as an argument and what does it return?

A

element you want to check as an argument, return is a boolean value.

75
Q

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

A

get attribute method.

76
Q

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

A

every step

77
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

create new event listener.

78
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 code for every index. You will have a big conditional block.

79
Q

What is JSON?

A

a standard text-based(string) format for representing structured data based on Javascript object syntax.

80
Q

What are serialization and deserialization?

A

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string. Deserialization is it inverse operation (converting string into object).

81
Q

Why are serialization and deserialization useful?

A

you can convert data into objects and vice versa.

Makes it possible to transfer data.

82
Q

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

A

using JSON.stringify.

83
Q

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

A

using JSON.parse.

84
Q

How do you store data inlocalStorage?

A

ocalStorage.setItem(‘ key name’, ‘name of variable’)

85
Q

How do you retrieve data fromlocalStorage?

A

using getItem method of localStorage object with an argument of the string of the name of the localStorage

86
Q

What data type canlocalStoragesave in the browser?

A

strings.

87
Q

When does the’beforeunload’event fire on thewindowobject?

A

before unload’ event is fired when the window, the document and its resources are about to be unloaded.

88
Q

What is amethod?

A

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

89
Q

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

A

Method definition is held by a variable, and method call
Actual code block with parameters.
Method call object.method(argument)

90
Q

Describe methoddefinitionsyntax (structure).

A

Var keyword, variable name, open curly brace for code block. Inside code block there are method name, colon and method function.

91
Q

Describe methodcallsyntax (structure).

A

Variablename, dot notation, method name followed by arguments.

92
Q

How is a method different from any other function?

A

Method is associated with objects, function is not.

93
Q

What is thedefining characteristicof Object-Oriented Programming?

A

There are functions inside the value of methods. Objects can contain both data and behavior.

94
Q

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

A

Abstraction, encapsulation, inheritance, polymorphism

95
Q

What is “abstraction”?

A

Making a model of something. Do something that is more complex than what the user sees.
Simple interaction mechanism.

96
Q

What does API stand for?

A

Application programming interface

97
Q

What is the purpose of an API?

A

Connects computers or pieces of software to each other.

98
Q

What isthisin JavaScript?

A

Keyword referring to the object that you are referring to. Implicitparameter.

99
Q

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

A

An implicit parameter, it is available in a function’s code block even though it was never included in the function’s parameter list or declared withvar

100
Q

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

A

Call time, if we are not using the tool yet, we have nothing to work with.

101
Q

How can you tell what the value ofthiswill be for a particular function or methoddefinition?

A

nothing.
Unless you are actively using the tool, this is nothing
It doesn’t exist.

102
Q

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

A

Find where the function is called and look for an object to the left of the dot.If you can’t see where the function (or method) is called, thenyou cannot say for sure what the value ofthisis.

103
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype based (or prototypal) inheritance.

104
Q

What is a prototype in JavaScript?

A

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

105
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

Going after the original prototype. Shared location that it will look for that information.

106
Q

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

A

Object prototype.

107
Q

What does thenewoperator do?

A

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

108
Q

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

A

Prototype property.

109
Q

What does theinstanceofoperator do?

A

theprototypeproperty of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

110
Q

What is a “callback” function?

A

Callback function is 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.

111
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(), is a method in which it sets a timer which executes a function or specified piece of code once the timer expires.

112
Q

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

A

setInterval(), method, offered on theWindowandWorkerinterfaces, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call.

113
Q

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

A

0, which mean immediately.

114
Q

What dosetTimeout()andsetInterval()return?

A

The returnedintervalIDis a numeric, non-zero value which identifies the timer created by the call tosetInterval(); this value can be passed toclearInterval()to cancel the interval.
The returnedtimeoutIDis a positive integer value which identifies the timer created by the call tosetTimeout(). This value can be passed toclearTimeout()to cancel the timeout.

115
Q

What is AJAX?

A

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

116
Q

What does the AJAX acronym stand for?

A

‘Asynchronous JavaScript and XML’

117
Q

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

A

Xmlhttprequest

118
Q

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

A

load

119
Q

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

A

they have a shared object in their prototypal chain.