Javascript Flashcards

1
Q

What is the purpose of variables?

A

To store data to be accessed later.

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

How do you declare a variable?

A

Var keyword variable Name; (var quantity;)

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 var Name = var value; (var quantity = 3;)

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, number, dollar sign, or underscore

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

Using the same variable name must have the same lowercase or uppercase 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

To store data made up of text

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 store numeric data / for tasks that involve counting or calculating

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 store true or false data / binary data.

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

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

Null is intentionally left with no value and undefined is declared to variables that have not been assigned a value yet.

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 add a description of the variable/value being logged.

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

Adding a string value with another value

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

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

It adds the value of the var on the right to the current value of the var on the left which then equals the var 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

To store multiple pieces of data in one variable / to organize data

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

What are object properties?

A

Individual variables stored in an object.

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

Describe object literal notation.

A

Var keyword variable name holding the object = { };

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

Delete operator . property name; OR delete property[‘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

Dot notation and bracket notation

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

What are arrays used for?

A

To store a list of values. (mainly for similar data)

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

Describe array literal notation.

A

Var keyword variableName = [ ];

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

The key for its’ value is a numeric index.

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

.length / holds the number of pieces of data 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

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

Special type of object that can be called. Set of reusable code.

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 optionalFuncName ( parameter, ) {
Optional Return;
}

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

functionName()

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

Call passes in argument/values .. definition has code block

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

What is the difference between a parameter and an argument?

A

Parameter is in definition(placeholder) and argument is in call(value).

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

Why are function parameters useful?

A

Gives more uses to the function since data can be passed in through the parameter.

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

Produce a value /

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 see if the code runs properly / check if any errors

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

What is a method?

A

A function stored within a property in an object.

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

How do you remove the last element from an array?

A

array.pop()

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

How do you delete an element from an array?

A

array.splice()

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

How do you append an element to an array?

A

.push() / .unshift()

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

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

A

No.

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

Not always.

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

36

48
Q

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

A

MDN

49
Q

Give 6 examples of comparison operators.

A

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

50
Q

What data type do comparison expressions evaluate to?

A

boolean.

51
Q

What is the purpose of an if statement?

A

to make a decision in the code.

52
Q

Is else required in order to use an if statement?

A

No.

53
Q

Describe the syntax (structure) of an if statement.

A

if (condition {
code to execute;
}

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

A

using logical operator.

56
Q

What is the purpose of a loop?

A

To check if a condition is true.

57
Q

What does the ++ increment operator do?

A

Increments by 1.

58
Q

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

A

Focus

59
Q

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

A

Blur

60
Q

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

A

Input

61
Q

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

A

Submit

62
Q

What does the event.preventDefault() method do?

A

Prevents page from refreshing

63
Q

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

A

Refreshed the page

64
Q

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

A

Elements property.

65
Q

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

A

Value property.

66
Q

What is one risk of writing a lot of code without checking to see if it works so far?

A

Harder to find where errors are happening.

67
Q

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

A

To know right away if you have a bug.

68
Q

What is JSON?

A

String format meant to replicate javascript objects

69
Q

What are serialization and deserialization?

A

Serialization - taking data and converting it into a string of bytes. deserialization is taking bytes and turn it back into an object

70
Q

Why are serialization and deserialization useful?

A

Makes it possible to transfer data.

71
Q

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

A

stringify method of the JSON object.

72
Q

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

A

parse method of the JSON object.

73
Q

How to you store data in localStorage?

A

localStorage.setItem()

74
Q

How to you retrieve data from localStorage?

A

localStorage.getItem()

75
Q

What data type can localStorage save in the browser?

A

string

76
Q

What is a method?

A

A functions that is a property of an object.

77
Q

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

A

Method definition is code block being assigned to a property and call is object .methodName.

78
Q

Describe method definition syntax (structure).

A
var keyword var name = {
method name: function keyword()
code block / return
}
79
Q

Describe method call syntax (structure).

A

object.methodName( );

80
Q

How is a method different from any other function?

A

Method is associated with objects.

81
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects contain data (as properties) as well as the behavior (as methods)

82
Q

What is “abstraction”?

A

Working with complex things in a simple way

83
Q

What does API stand for?

A

Application Programming Interface

84
Q

What is the purpose of an API?

A

connect two computers or softwares

85
Q

What is the purpose of an API?

A

Collection of tools for somebody else to use. Abstraction.

86
Q

What is this in JavaScript?

A

Keyword referring to an object - which you are doing work in / Implicit parameter of all JavaScript functions

87
Q

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

A

It is available to use in the function even though it was never included as a parameter or declared with var.

88
Q

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

A

Call time.

89
Q

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

A

You can’t.

90
Q

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

A

method - The object to the left of the dot. function - window.

91
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype based (prototypal)

92
Q

What is a prototype in JavaScript?

A

An original model of which something is patterned and added more unique features

93
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

It is a shared location

94
Q

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

A

Looks in the object prototype

95
Q

What does the new operator do?

A

Creates new object, adds new object (__proto__), binds created object as the “this” constructor function, returns “this”

96
Q

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

A

prototype

97
Q

What does the instanceof operator do?

A

Checks if thing on the left is the same as the proto type of the var on the right.

98
Q

What is a “callback” function?

A

a function passed into another function as an argument, thats called inside the outer function

99
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

Using the setTimeout( ) method

100
Q

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

A

setInterval() method

101
Q

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

A

0

102
Q

What do setTimeout() and setInterval() return?

A

Number that identifies the interval or timeout

103
Q

What is a client?

A

Something that is requesting information.

104
Q

What is a server?

A

The server provides/responds the information and is listening for requests.

105
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET Method

106
Q

What three things are on the start-line of an HTTP request message?

A

The method, the target, and the HTTP version

107
Q

What three things are on the start-line of an HTTP response message?

A

Protocol version, status code, and status text

108
Q

What are HTTP headers?

A

Additional information for descriptions.

109
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

MDN

110
Q

Is a body required for a valid HTTP request or response message?

A

NO

111
Q

What is AJAX?

A

programming practice of building complex, dynamic webpages using XMLHttpRequest

112
Q

What does the AJAX acronym stand for?

A

Asynchronous Javascript And XML

113
Q

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

A

XHR object

114
Q

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

A

Load Event

115
Q

An XMLHttpRequest object has an addEventListener() 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.