JavaScript Flashcards

1
Q

What is the purpose of variables?

A

used 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

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

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

can contain letters, digits, underscores, $

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

This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters (camelCase)

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

datatype consists of

letters and other characters; store text data

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

store numeric data

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

used to create true/false statements.

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

reassignment; the var keyword would no longer be in the statement

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

an undefined variable has been declared but not defined yet. null is an assigned value of nothing

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

Give five examples of JavaScript primitives.

A

number, strings, booleans, null, undefined

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

What is string concatenation?

A

adding strings together

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

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

A

adds one value to another or concatenates strings

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

boolean

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

Addition assignment

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

What are objects used for?

A

group together related data to create a model

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

What are object properties?

A

unique named keys paired to values

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

Describe object literal notation.

A

made up of object name followed by key and value pairs wrapped in curly braces

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

delete object.property

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

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

A

using dot notation or square brackets

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

What are arrays used for?

A

store a list of values

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

Describe array literal notation.

A

array name followed by the assignment operator then square brackets with values separated by commas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How are arrays different from "plain" objects?
arrays have order and methods for updating the array
26
What number represents the first index of an array?
0
27
What is the length property of an array?
results in the number of items in an array
28
How do you calculate the last index of an array?
array.length - 1
29
What is a function in JavaScript?
block of code designed to perform a particular task
30
Describe the parts of a function definition.
begins with a function keyword, followed by a name (optional), then parameters in parentheses, then open curly brace to start code block, optional return statement, ends with closing curly brace
31
Describe the parts of a function call.
function name followed by parentheses
32
When comparing them side-by-side, what are the differences between a function call and a function definition?
``` function definition begins with the function keyword, contains curly braces, and an optional return statement. function call only has function name and arguments inside parentheses. ```
33
What is the difference between a parameter and an argument?
parameters serve as a placeholder in the function definition and arguments are passed when a function is called
34
Why are function parameters useful?
the parameter will be holding the value of the argument when the function's code block is run
35
What two effects does a return statement have on the behavior of a function?
causes the function to produce a value and it exits the function code block
36
What is a method?
a function which is a property of an object
37
How is a method different from any other function?
methods are attached to objects
38
How do you remove the last element from an array?
.pop()
39
How do you round a number down to the nearest integer?
Math.floor()
40
How do you generate a random number?
Math.random()
41
How do you delete an element from an array?
.splice()
42
How do you append an element to an array?
.push()
43
How do you break a string up into an array?
.split()
44
Do string methods change the original string? How would you check if you weren't sure?
strings are immutable and check with console.log() or documentation
45
Is the return value of a function or method useful in every situation?
no
46
Give 6 examples of comparison operators.
=== , > , < , !=, >=, <=
47
What data type do comparison expressions evaluate to?
boolean
48
What is the purpose of an if statement?
evaluate condition
49
Is else required in order to use an if statement?
no
50
Describe the syntax (structure) of an if statement.
begins with if followed by the condition in parentheses, then open curly brace for code block to be executed and closed with curly brace
51
What are the three logical operators?
&&, ||, !
52
How do you compare two different expressions in the same condition?
using logical operators
53
What is the purpose of a loop?
checks a condition and repeats a task if the value is truthy
54
What is the purpose of a condition expression in a loop?
gives us a stopping point
55
When does the condition expression of a while loop get evaluated?
evaluated before each iteration
56
When does the initialization expression of a for loop get evaluated?
evaluated once before the loop begins
57
When does the condition expression of a for loop get evaluated?
before each loop iteration/code block
58
When does the final expression of a for loop get evaluated?
after code block and before the condition
59
which keyword exits a loop before its condition expression evaluates to false?
break
60
What does the ++ increment operator do?
adds one to its operand and returns a value
61
How do you iterate through the keys of an object?
using for.. in loops
62
What event is fired when a user places their cursor in a form control?
'focus'
63
What event is fired when a user's cursor leaves a form control?
'blur'
64
What event is fired as a user changes the value of a form control?
'input'
65
What event is fired when a user clicks the "submit" button within a form?
'submit'
66
What does the event.preventDefault() method do?
its default action should not be taken as it normally would be
67
What does submitting a form without event.preventDefault() do?
refreshes the page and information entered remains in the URL
68
What property of a form element object contains all of the form's controls?
elements
69
What property of form a control object gets and sets its value?
value
70
What is an advantage of having your console open when writing a JavaScript program?
fix errors when they occur
71
What is JSON?
a standard text-based format for representing structured data based on JavaScript object syntax
72
What are serialization and deserialization?
serialization is converting a native object to a string; deserialization is converting a string to a native object
73
Why are serialization and deserialization useful?
network transmission; | deserialization helps store data as a string; serialization is used to access data
74
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
75
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
76
How do you store data in localStorage?
localStorage.setItem('key', 'value')
77
How do you retrieve data from localStorage?
localStorage.getItem('keyname')
78
What data type can localStorage save in the browser?
string data
79
When does the 'beforeunload' event fire on the window object?
when the window, the document and its resources are about to be unloaded
80
What is a method?
a function which is a property of an object.
81
How can you tell the difference between a method definition and a method call?
method definition starts with the function keyword followed by curly braces and a coding block being assigned to property; method call is object.method() parentheses can have arguments;
82
Describe method definition syntax (structure)
key name : function (parameters) followed by curly braces and code block
83
Describe method call syntax (structure)
object.method(arguments)
84
How is a method different from any other function?
method is a property of an object
85
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods)
86
What is "abstraction"?
a way of creating a simple model of important properties;being able to work with (possibly) complex things in simple ways
87
What does API stand for?
application programming interface
88
What is the purpose of an API?
simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs
89
What is this in JavaScript?
keyword refers to the object it currently belongs to
90
What does it mean to say that this is 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
91
When is the value of this determined in a function; call time or definition time?
call time
92
``` 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); } }; ```
character object
93
``` what is the result of the following code snippet? Why var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; ``` character.greet();
'it's a-me, Mario!'
94
``` what is the result of the following code snippet? Why? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } }; ``` ``` var hello = character.greet; hello(); ```
'it's a-me, undefined!' bc the greet method is being stored in the new variable. the this keyword does not have any object to relate to. there is no object left to the dot of hello
95
How can you tell what the value of this will be for a particular function or method definition?
you don't know what the value of this will be until function is called
96
How can you tell what the value of this is for a particular function or method call?
"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.
97
What kind of inheritance does the JavaScript programming language use?
prototype based inheritance (prototypal)
98
What is a prototype in JavaScript?
an object that contains properties and (predominantly) methods that can be used by other objects
99
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?
methods are borrowed from prototype objects
100
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
prototype object
101
What does the new operator do?
create an instance of a user-defined object type or of one of the built-in object types that has a constructor function
102
What property of JavaScript functions can store shared behavior for instances created with new?
function.prototype property
103
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
104
What is a "callback" function?
a function passed into another function as an argument
105
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?
setInterval() or setTimeout()?
106
How can you set up a function to be called repeatedly without using a loop?
setInterval()
107
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
108
What do setTimeout() and setInterval() return?
interval ID
109
What is AJAX?
a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest
110
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
111
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
112
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
113
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
prototypal inheritance