Javascript Flashcards

1
Q

What is the purpose of variables?

A

to use 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

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

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

What character are allowed in a variable name?

A

letter, $, underscore _, number but not start with a number

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

different variables if casing is different

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

arguments

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

numerical value

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

true/false, data type

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

How do you update the value of a variable?

A

var name = value, no need to add var in front of var name

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

What is the difference between null and undefined?

A

null needs to be purposefully assigned made to be empty to be filled later

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

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

A

easier to debug later

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

Give five examples of Javascript primitives?

A

string, number, boolean, null, undefined

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, null, undefined

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

numerical

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

What is string concatenation?

A

tie two strings together

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

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

A

concatenation, add +

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

What data type if 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

addition assignment, take result as new value

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

What are objects used for?

A

grouping multiple properties with values that are related to each other

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

What are objects properties?

A

variables glued to objects

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

Describe object literal notation.

A

arraysof properties to their values

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 object.property

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

property.nameOfvalue, or property[‘nameOfvalue’], and delete property.nameOfvalue

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

What are arrays used for?

A

lists of the same purpose/context rather than related

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

Describe array literal notation.

A

square brackets separated in commas

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

arrays have number indexes, objects have key/named values/properties (arrays also have an order, objects and their properties do not)

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, first to last # of the list/array (or total count)

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

using length property (.length) -1 , because indexes start at 0 , length count starts at 1

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

function function name , return

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

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

functions definition contain the action, function calls are invoking the function to be used

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 are present function definitions, arguments are present during function calls

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

Why do we log things to the console?

A

debugging

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

what is a method?

A

a way to do things

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

What is the purpose of an if statement?

A

gives a requirement in order to achieve the result

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

Is else required in order to use an if statement?

A

no

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

What is the purpose of a loop?

A

repeatedly run a block of code until a defined condition is met

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

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

A

When to continue, and when to end

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

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

A

in the beginning, once

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

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

A

break statement

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

What does ++ increment operator do?

A

adds one (push 1)

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

How do you interate through the keys of an object?

A

for…in loops

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

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

A

focus

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

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

A

blur

46
Q

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

A

input

47
Q

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

A

submit

48
Q

What does the event.preventDEfault() method do?

A

non cancellable event

49
Q

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

A

prevent the browser from automatically reloading the page with the form’s values in the URL.

50
Q

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

A

elements property

51
Q

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

A

name

52
Q

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

A

value

53
Q

How to you store data in localstorage?

A

setItem

54
Q

How do you retrieve data from localStorage?

A

getItem

55
Q

What data type can localStorage save in the browser?

A

strings

56
Q

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

A

right before you exit/refresh the page

57
Q

What is a method?

A

method is a function being assigned to an object

58
Q

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

A

method is being paired to an object, function call is separate

59
Q

Describe method definition syntax (structure).

A

Block of code being passed through a function with a parameter, assigned to a method name

60
Q

Describe method call syntax (structure).

A

object.methodname

61
Q

How is a method different from any other function?

A

Associated with an object, other function is independent

62
Q

What is the defining characteristic of Object-Oriented programming?

A

data paired with methods

63
Q

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

A

Encapsulation, Data Abstraction, Polymorphism and Inheritance

64
Q

What is “abstraction”?

A

process of hiding the implementation details and displaying only the functionality

65
Q

What does API stand for?

A

Application Programming Interface

66
Q

What is the purpose of an API?

A

tools available to a program

67
Q

What is “this” in Javascript?

A

key word of the object you’re currently working with

68
Q

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

A

no paramter in a function, “this” is being used instead

69
Q

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

A

only has the value when the function is being called

70
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

none, no function being called

71
Q

Given the above character object, what is the result of the following code snippet? Why? character.greet();

A

calling on the function assigned to the property green of the character object.

72
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

it’s a me undefined, because no function in greet

73
Q

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

A

can’t know a definition

74
Q

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

A

object left of the dot, the window

75
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype

76
Q

What is prototype in Javascript?

A

what objects can build off of

77
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

grab prototypes

78
Q

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

A

on the prototypes

79
Q

What does the ‘new’ operator do?

A

lets us create objects with a function

80
Q

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

A

prototype

81
Q

What does the instanceof operator do?

A

checks if x is in y

82
Q

What is AJAX?

A

seeking out data to develop more content once a page already loaded

83
Q

What does the AJAX acroynm stand for?

A

A synchronous J avaScript A nd X ML

84
Q

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

A

XMLHttpRequest

85
Q

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

A

load

86
Q

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

A

both share a prototype

87
Q

How is method different from any other function?

A

methods are attached to objects

88
Q

How do you remove the last element from an array?

A

.pop()

89
Q

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

A

Math.floor()

90
Q

How do you generate a random number?

A

Math.random()

91
Q

How do you delete an element from an array?

A

.splice()

92
Q

How do you append an element to an array?

A

.push()

93
Q

How do you break a string up into an array?

A

.split()

94
Q

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

A

no, check through console.log

95
Q

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

A

~30 (not really important, just know it’s a lot)

96
Q

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

A

no

97
Q

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

A

~35 (not really important, just know it’s a lot)

98
Q

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

A

MDN

99
Q

Give 6 examples of comparison operators.

A

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

100
Q

What data type do comparison expressions evaluate to?

A

boolean

101
Q

What is the purpose of an if statement?

A

to make a condition, should do or not

102
Q

is else required to used an if statement?

A

no

103
Q

What are the three logical operators?

A

&& , ||, ! (not)

104
Q

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

A

in the if statement, you have two expressions with logical operators separating them within the condition

105
Q

What is the purpose of a loop?

A

To traverse through and have a repeated action until you’re done

106
Q

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

A

to check if we should still keep running the loop

107
Q

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

A

passing through a loop once

108
Q

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

A

When it’s still true, before the code block executes

109
Q

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

A

in the beginning only once

110
Q

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

A

second after the initialization, then after the incrementing until condition is no longer true

111
Q

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

A

after the condition until loop is no longer needed

112
Q

What does the ++ increment operator do?

A

increment by 1