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
Q

How are arrays different from “plain” objects?

A

arrays have order and methods for updating the array

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

results in the number of items 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.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

block of code designed to perform a particular task

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

Describe the parts of a function definition.

A

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

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

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

What is the difference between a parameter and an argument?

A

parameters serve as a placeholder in the function definition and arguments are passed when a function is called

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

Why are function parameters useful?

A

the parameter will be holding the value of the argument when the function’s code block is run

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

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

A

causes the function to produce a value and it exits the function code block

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

How is a method different from any other function?

A

methods are attached to objects

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

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

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

strings are immutable and check with console.log() or documentation

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

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

A

no

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

Give 6 examples of comparison operators.

A

=== , > , < , !=, >=, <=

47
Q

What data type do comparison expressions evaluate to?

A

boolean

48
Q

What is the purpose of an if statement?

A

evaluate condition

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

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
Q

What are the three logical operators?

A

&&, ||, !

52
Q

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

A

using logical operators

53
Q

What is the purpose of a loop?

A

checks a condition and repeats a task if the value is truthy

54
Q

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

A

gives us a stopping point

55
Q

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

A

evaluated before each iteration

56
Q

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

A

evaluated once before the loop begins

57
Q

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

A

before each loop iteration/code block

58
Q

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

A

after code block and before the condition

59
Q

which keyword exits a loop before its condition expression evaluates to false?

A

break

60
Q

What does the ++ increment operator do?

A

adds one to its operand and returns a value

61
Q

How do you iterate through the keys of an object?

A

using for.. in loops

62
Q

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

A

‘focus’

63
Q

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

A

‘blur’

64
Q

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

A

‘input’

65
Q

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

A

‘submit’

66
Q

What does the event.preventDefault() method do?

A

its default action should not be taken as it normally would be

67
Q

What does submitting a form without event.preventDefault() do?

A

refreshes the page and information entered remains in the URL

68
Q

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

A

elements

69
Q

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

A

value

70
Q

What is an advantage of having your console open when writing a JavaScript program?

A

fix errors when they occur

71
Q

What is JSON?

A

a standard text-based format for representing structured data based on JavaScript object syntax

72
Q

What are serialization and deserialization?

A

serialization is converting a native object to a string; deserialization is converting a string to a native object

73
Q

Why are serialization and deserialization useful?

A

network transmission;

deserialization helps store data as a string; serialization is used to access data

74
Q

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

A

JSON.stringify()

75
Q

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

A

JSON.parse()

76
Q

How do you store data in localStorage?

A

localStorage.setItem(‘key’, ‘value’)

77
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(‘keyname’)

78
Q

What data type can localStorage save in the browser?

A

string data

79
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

80
Q

What is a method?

A

a function which is a property of an object.

81
Q

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

A

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
Q

Describe method definition syntax (structure)

A

key name : function (parameters) followed by curly braces and code block

83
Q

Describe method call syntax (structure)

A

object.method(arguments)

84
Q

How is a method different from any other function?

A

method is a property of an object

85
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

86
Q

What is “abstraction”?

A

a way of creating a simple model of important properties;being able to work with (possibly) complex things in simple ways

87
Q

What does API stand for?

A

application programming interface

88
Q

What is the purpose of an API?

A

simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs

89
Q

What is this in JavaScript?

A

keyword refers to the object it currently belongs to

90
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

91
Q

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

A

call time

92
Q
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);
  }
};
A

character object

93
Q
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();

A

‘it’s a-me, Mario!’

94
Q
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();
A

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

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

A

you don’t know what the value of this will be until function is called

96
Q

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

A

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

What kind of inheritance does the JavaScript programming language use?

A

prototype based inheritance (prototypal)

98
Q

What is a prototype in JavaScript?

A

an object that contains properties and (predominantly) methods that can be used by other objects

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

methods are borrowed from prototype objects

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

prototype object

101
Q

What does the new operator do?

A

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

102
Q

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

A

function.prototype property

103
Q

What does the instanceof operator do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

104
Q

What is a “callback” function?

A

a function passed into another function as an 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

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

0

108
Q

What do setTimeout() and setInterval() return?

A

interval ID

109
Q

What is AJAX?

A

a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest

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

prototypal inheritance