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

Using the variable keyword and 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

Write the variable name, and use the assignment operator to assign it to a 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

The name can contain letters, numbers, dollar sign ($), or an 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

the capitalization must be consistent

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

The String object is used to represent and manipulate a sequence 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

represent and manipulate numbers

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 hold data types of true or false

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

assign a value into a variable

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

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

undefined has not been assigned a value yet. null intentionally has no value.

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

helpful to debug

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 and 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 value

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

What is string concatenation?

A

to add two strings so they become a single 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

to add numeric values or concatenate one string into 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

adds the value of the right operand to a variable and assigns the result to the variable.

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

What are objects used for?

A

group together a set of variables and functions

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

What are object properties?

A

variable that is attached to the object and we can store data

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

Describe object literal notation.

A

variable, assigning operator , curly braces, and collection of property and 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

use the delete keyword followed by the object name and 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

using dot notation or 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

It stores a list of values

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

Describe array literal notation.

A

variable keyword, variable name, assignment operator, square brackets with the values inside 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

object: Property name and value, array: numeric index and value

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

The number of items 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

arrayName.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

a procedure—a set of statements that performs a task or calculates a value

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 function’s name.
() parentheses, with the arguments inside

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

function definition has the function keyword and a block of code. whereas function call has only the function name followed by the parentheses

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

Parameters are variables listed as a part of the function definition. · Arguments are values passed to the function when it is invoked.

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

Why are function parameters useful?

A

They allow a function to work with different data depending on what values are passed to the function when it is called.

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

exits the function’s code block and returns control to the calling function

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 what our data is

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

What is a method?

A

A method is 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

The difference is that a method is associated with an object, while a function is not.

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

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

Math.floor() method

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

Math.random() method

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 splice, pop shift slice 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 or unshift method

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, they do not. Using console.log

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

50

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

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

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

A

40

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

Give 6 examples of comparison operators.

A

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

51
Q

What data type do comparison expressions evaluate to?

A

Boolean value

52
Q

What is the purpose of an if statement?

A

guides a program to make decisions based on specified criteria.

53
Q

Is else required in order to use an if statement?

A

No

54
Q

Describe the syntax (structure) of an if statement.

A

if keyword, condition expression (), curly braces, and code block

55
Q

What are the three logical operators?

A

&& and, ||or and !(bang operator)

56
Q

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

A

&& or ||

57
Q

What is the purpose of a loop?

A

Check a condition, perform a task a until it breaks a condition

58
Q

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

A

stop running if does not satisfy the codition

59
Q

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

A

each time the loop runs

60
Q

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

A

before executing the expression

61
Q

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

A

before any loop action happens

62
Q

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

A

before each iteration

63
Q

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

A

after each iteration.

64
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. It exists a running loop but it does not exit a function like the ‘return’ statement

65
Q

What does the ++ increment operator do?

A

Increment by one

66
Q

How do you iterate through the keys of an object?

A

Using for in method

67
Q

What are the four components of “the Cascade”.

A

Source Order,Inheritance, Specificity & !important,

68
Q

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

A

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

69
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

inheritance. most common: fonts and color

70
Q

List the three selector types in order of increasing specificity.

A

element, class and ID

71
Q

Why is using !important considered bad practice?

A

it breaks the natural CSS cascading in stylesheets and is difficult to debug

72
Q

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

A

focus event

73
Q

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

A

‘blur’

74
Q

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

A

‘input’

75
Q

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

A

‘submit’

76
Q

What does the event.preventDefault() method do?

A

prevent the browser from automatically reloading the page

77
Q

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

A

it causes the form to refresh the page and to submit the data

78
Q

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

A

elements property

79
Q

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

A

the value property

80
Q

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

A

Hides the element and completely removes the element from the document. So it will no longer have any relationship to any other elements that are on the screen.

81
Q

What does the element.matches() method take as an argument and what does it return?

A

Takes a CSS selector. It returns true or false

82
Q

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

A

By using the getAttribute method and then passing in whatever attribute that we’re trying to access the value of.

83
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

If we’re not using event delegation, that would require that we add an eventListener to each new tab we created. One of the huge benefits of event delegation is to list on the parent and no matter how many children we have, the parent can respond to all of those events.

84
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

If/else statement that will check each element

85
Q

How do you store data in localStorage?

A

Use setItem method

86
Q

How do you retrieve data from localStorage?

A

getItem method

87
Q

What data type can localStorage save in the browser?

A

JSON String

88
Q

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

A

Right before the page is loaded

89
Q

What is a method?

A

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

90
Q

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

A

Method call indicates when a method of an object is being called.
Method definition is when you define a function property in an object.

91
Q

Describe method definition syntax (structure).

A

an object, a property, colon, function and block code

92
Q

Describe method call syntax (structure).

A

object name.method(arg)

93
Q

How is a method different from any other function?

A

a method is associated with an object, while a function is not

94
Q

What is the defining characteristic of Object-Oriented Programming?

A

Object can contain not only data and value but functionality in the form of methods.

95
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism

96
Q

What is “abstraction”?

A

Taking something that is complex from the user perceptive and simplifying it.

97
Q

What does API stand for?

A

Application programming interface.

98
Q

What is the purpose of an API?

A

to create an accessible way to extract and share data within and across organizations.

99
Q

What is this in JavaScript?

A

This refers to the object that was generated by a constructor and its going to refer to itself.
Refers to the calling object. Whatever object that is calling the function. ‘This’ is going to be defined based on who is calling the function.

100
Q

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

A

it is available in the function’s code block even though it was never declared or included in the function’s parameter list

101
Q

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

A

Call time

102
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

The object ‘character’.

103
Q

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

A

Its’ -a-me Mario. Because The character is the calling object.
And the character object has firstName property.

104
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 the rest of the properties of the ‘character’ object, like firstName, was not saved into the hello variable. ‘Hello’ its not attached into an object, it gets attached to the window object. And the window object does not have a firstName property on it.

105
Q

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

A

We could assume but we can not know.

106
Q

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

A

If we can see the object that is calling it,’this’ will refer to that object

107
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance

108
Q

What is a prototype in JavaScript?

A

An object that contains the functionality that you want to prototype into another object. Basically, a framework of functionality that you can use to attach to any object that you create.

109
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

Because of prototyping we can call those methods.

110
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” chain

111
Q

What does the new operator do?

A

The new keyword is for creating new object instances.

112
Q

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

A

prototype

113
Q

What does the instanceof operator do?

A

tests to see if the prototype of a constructor appears in the prototype of an object.

114
Q

What is a “callback” function?

A

callback function is a function passed into another function as an argument

115
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

setTimeout function

116
Q

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

A

Using setInterval() function

117
Q

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

A

a value of 0, meaning its ready to be called. does not mean that it will be executed immediately

118
Q

What do setTimeout() and setInterval() return?

A

positive integer value

119
Q

What is AJAX?

A

Asynchronous JavaScript And XML is a programming practice that allows you to collect data to update parts of the DOM of an HTML page without the need for a full page refresh

120
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

121
Q

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

A

new XMLHttpRequest()

122
Q

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

A

xhr.addEventListener(‘load’)

123
Q

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

A

They share a prototype