Javascript Flashcards

1
Q

what is the purpose of variables?

A

to declare a value.

to store info to be referenced

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 var, let, const 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

add an equal sign and put the 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

No other characters are permitted in the variable name. Specifically, spaces are not permitted in the variable names, as variable name must be a single word. Variable name may not start with a digit or underscore, and may not end with an underscore. Double underscores are not permitted in variable name.

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

Uppercase and lowercase letters are treated as distinct

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 or indicate text value

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 or indicate 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

to store or indicate true/false value

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

assigning a value

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

by assigning a different value that you want

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

a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address.

undefined is that, there’s no value in it.

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 make debugging easier.

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

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
  • numeric data type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is string concatenation?

A
  • connecting strings by using +. combining strings.

- strings are immutable in javascript. (not mutable, it cannot change)

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

what purpose does the + plus operator serve?

A

concatenating strings or add numeric values with arithmetic operators.

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?

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

add value to the variable and store the value in the same variable

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

what are objects used for?

A

JavaScript objects are containers for named values, called properties and methods.

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

what are object properties?

A

association between key and value

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

Describe object literal notation

A

The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array.

  • opening and closing curly brases
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

by using the delete keyword

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

adding keys by using dot notation or add inside the object directly.

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

what are arrays used for ?

A

it is used for storing different elements

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

describe array literal notation

A

array literal notation is where you define a new array using just empty brackets.

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

you can get values by indicating the index.?

  • doesnt need a name key.
  • have a property name length and is automatically updated when adding a new value.
  • list .
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

what number represents the first index of 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

get the total number of values

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

total 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 block of code designed to perform a particular task.

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, a comma-separated list of zero or more parameters, surrounded by parentheses. The start of the function’s code block, an optional return statement. the end of the function’s code block.

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

write the function name and parentheses next to it. pass an argument to the function

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

describe the parts of a function call

A

write the function name and parentheses next to it. pass an argument to it?

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

what are the differences between a function call and a function definition?

A

calling a function means executing it.

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

what is the difference between a parameter and an argument?

A

Parameter is variable in the declaration of function.

Argument is the actual value of this variable that gets passed to function.

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

why are function parameters useful?

A

A function can take parameters which are just values you supply to the function so that the function can do something utilising those values.

reusing values for other purposes?

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

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

A

The return statement ends function execution and specifies a value to be returned to the function caller

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

why do we log things to the console.?

A

to see the result value and for debugging

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

what is the method?

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

how is a method different from any other function?

A

function themselves are objects, so, in that context, a method is actually an object reference to a function.

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

How do you remove the last element from an array?

A

use the pop() method.

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

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

A

Math.floor() bring it down to the nearest integer.

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

How do you delete an element from an array?

A

splice(start, deleteCount, item1)

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

do string methods change the original string? how would you check if you weren’t sure?

A

All string methods return a new string. They don’t modify the original string. Formally said: Strings are immutable: Strings cannot be changed, only replaced.

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

roughly how many string methods are there according to the MDN web docs?

A

45-50 methods.

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

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

A

sometimes. push() method is just to add an element to the array

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

roughly how many array methods are there according to the MDN web docs?

A

many many

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

what three letter acronym should you always include in your google search about a javascript method or css property?

A

MDN

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

Give six examples of comparison operators.

A

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

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

what data type do comparison expressions evaluate to?

A

boolean, true or false

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

what is the purpose of an ‘if’ statement?

A

to declare a condition within the function

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

Is ‘else’ required in order to use an ‘if’ statement?

A

not always.

56
Q

describe the syntax of an ‘if’ statement

A

if (condition) {

}

57
Q

what are the three logical operators?

A

and / or / not

58
Q

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

A

adding add (&&) or OR (||) with two conditions

59
Q

what is the purpose of a loop?

A

Loops are used in JavaScript to perform repeated tasks based on a condition.

60
Q

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

A

Conditional statements control behavior in JavaScript and determine whether or not pieces of code can run

61
Q

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

A

a step where some action is repeated

62
Q

when does the condition expression of a ‘while’ loop get evaluated?

A

An expression evaluated before each pass through the loop.
If this condition evaluates to true, statement is executed.
When condition evaluates to false, execution continues with the statement after the while loop.

63
Q

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

A

start point of the loop.

64
Q

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

A

after the initializtion and the condition

65
Q

when does the final expression of a for loop get evaluate?

A

after the code block is done and after the next condition is executed?

66
Q

Besides the return statement, which exits its entire function block?

A

break;

67
Q

what does the ++ increment operator do?

A

adds number one, re-assigns and substitutes in its value.

68
Q

how do you iterate through the keys of an object?

A

use the ‘for in ‘ loops

69
Q

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

A

focus

70
Q

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

A

blur

71
Q

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

A

input

72
Q

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

A

submit event

73
Q

what does the event.preventDefault() method do?

A

it tells the user agent that if the event does not get explicitly handed, its default action should not be taken as it normally would be. (prevents the default action in event - example: refreshing the form)

necessary for every submit event in forms

74
Q

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

A

elements property

75
Q

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

A

value property

76
Q

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

A

hard to debug

77
Q

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

A

you can check the values one at a time.

78
Q

what is the event.target?

A

the element that triggered the event

79
Q

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

A

display: none; When you set the value of display to none, the affected element will disappear. This means the element will no longer take up any space on the web page.

no longer visible and removed from the document flow

80
Q

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

A

You invoke the matches() method on the element itself (the element has to be an HTML element), and like querySelector / querySelectorAll , you pass the selector as a string argument. The method returns true for a match, and false otherwise.

81
Q

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

A

Get the value of an attribute of a specified element by calling the getAttribute() method on the element. The getAttribute() returns null if the attribute does not exist.

82
Q

At what steps of the solution would it be helpful to log things to the console?

A

all steps for the solution

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

Individually apply each event handlers for each element

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

we would have to add each if statement for every element

85
Q

what is JSON?

A

JavaScript Object Notation

a standard text-based format for representing structured data based on Javascript object syntax. It is commonly used for transmitting data in web applications (sending some data from the server to the client, so it can be displayed on a web page)

86
Q

what are serialization and deserialization ?

A

Serialization is the process of turning an object in memory => into a stream of bytes so you can do stuff like store it on a disk or send it over the network

Deserialization is the reverse process.

87
Q

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

A

JSON.stringify()

88
Q

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

A

JSON.parse()

89
Q

why are serialization and deserialization useful?

A

Its main purpose is to save the state of an object in order to be able to recreate it when needed.

transferring the bytes. transfer through network and save it to hard-drive

90
Q

How do you store data in ‘localStorage’?

A

localStorage.setItem(key, value);

91
Q

How do you retrieve data from localStorage?

A

localStorage.getItem(key)

92
Q

what data type can ‘localStorage’ save in the browser?

A

string type

93
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.
the document is still visible and the event is still cancelable at this point

94
Q

what is a method?

A

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

Instance methods: built-in tasks performed by an object instance
Static methods: tasks that are called directly on an object constructor

95
Q

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

A

declare and define are the same, and they mean when you write all the code for your function. At that point the function just sits there doing nothing. call is when you tell the JavaScript interpreter to run the code in your function.

96
Q

Describe method definition syntax (structure).

A
var something = {
add: function(x, y) {
return result
}
}
97
Q

Describe method call syntax(structure)

A

something.add()

98
Q

How is a method different from any other function?

A

A function is independent, whereas a method is a function linked with an object. Explicit data is passed on to a function, whereas a method completely passes the object on which it was called in the program. A method is Object-oriented programming while a function has standalone functionality.

99
Q

what are the four principles of OOP?

A

Abstraction, Encapsulation, Inheritance, Polymorphism

100
Q

what is the defining characterisitic of OOP?

A

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

101
Q

What is abstraction?

A

being able to work with complex things in simple ways

102
Q

what does API stand for?

A

Application Programming Interface(API)

103
Q

what is the purpose of an API?

A

API stands for Application Programming Interface. The purpose of API is to establish communication between two software. (SOFTWARE ABSTRACTION)

For example, let’s say you have typed in some information on your phone. Now, this input information goes to the server, and the server process the data. After processing the data it sends the data to your phone. Your phone interprets the data and interprets the data to you.

All this happens is through API. So this is the use case of API. API are just codes that help to communicate between several programming g interfaces.

https://www.quora.com/What-is-the-purpose-of-API

104
Q

what is ‘this’ in javascript?

A

In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called).

The this keyword refers to different objects depending on how it is used: In an object method, this refers to the object.

105
Q

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

A

this is different from explicit parameters: it’s an implicit parameter, meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var.

you dont have to define it

106
Q

‘when’ is the value of ‘this’ determined in a function?

A

call time

-> just like explicit parameters, the value of this is determined when the function is called, not when it is defined. By default, when you call a function, it’s this will be given the value of the global window object.

107
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 variable -> no. becuz its not being called. -> so its nothing. (parameters do not have a value, it doesn’t exist)

108
Q

Given the above character object, what is the result of the following code snippet? Why?

character.greet();

A

the greeting message. “Its me, mario” - why?

becuz we’re calling the greet method of the character object

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

undefined. window does not have a firstName property.

110
Q

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

A

you cant. there’s no way cuz its not being used yet.

111
Q

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

A

the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method).

112
Q

What kind of inheritance does the JavaScript programming language use?

A

JavaScript includes a specific kind of inheritance known as prototype-based (or prototypal) inheritance. JavaScript objects give certain behaviors (methods) or data (properties) to other objects.

113
Q

what is a prototype in JavaScript?

A

The prototype is an object that is associated with every functions and objects by default in JavaScript, where function’s prototype property is accessible and modifiable and object’s prototype property (aka attribute) is not visible. … Every function includes prototype object by default.

114
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

make a prototype and set the prototype to the object.

115
Q

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

A

proto

116
Q

what does the ‘new’ operator do?

A

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

117
Q

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

A

prototype property

118
Q

what does the ‘instanceof’ operator do?

A

the instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.

119
Q

what is a callback function?

A

a callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

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

121
Q

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

A

setInterval() function

122
Q

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

A

value of zero meaning immediately.

123
Q

What do setTimeout() and setInterval() return?

A

The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

124
Q

what is ajax?

A

Asynchronous JavaScript And XML.

web application that sends and receive information without refreshing the page.

it is the use of the XMLHttpRequest object to communicate with servers. It can send and receive information in various formats, including JSON, XML, HTML, and text files. AJAX’s most appealing characteristic is its “asynchronous” nature, which means it can communicate with the server, exchange data, and update the page without having to refresh the page.

125
Q

what does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML.

126
Q

which object is built into the browser for making HTTP requests in javascript?

A

XMLHttpRequest()

127
Q

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

A

load

128
Q

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

A

Prototype inheritance.

Inherits properties of XMLHttpRequestEventTarget and of EventTarget

Element, and its children, as well as Document and Window, are the most common event targets, but other objects can be event targets, too. For example XMLHttpRequest, AudioNode, and AudioContext are also event targets.

129
Q

What is Array.prototype.filter useful for?

A

Array.prototype.filter() The filter() method creates a new array with all elements that pass the test implemented by the provided function.

130
Q

What is Array.prototype.map useful for?

A

map() The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

131
Q

What is Array.prototype.reduce useful for?

A

Array.prototype.reduce() The reduce() method executes a user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

132
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

function

133
Q
What does this code do?
const wrap = value => () => value;
A

returns value function

134
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it’s defined (lexical scope)

135
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closures