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
describe array literal notation
array literal notation is where you define a new array using just empty brackets.
26
how are arrays different from "plain" objects?
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 .
27
what number represents the first index of array?
0
28
what is the length property of an array?
get the total number of values
29
how do you calculate the last index of an array?
total length - 1
30
what is a function in javascript?
a block of code designed to perform a particular task.
31
describe the parts of a function definition
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.
32
describe the parts of a function call
write the function name and parentheses next to it. pass an argument to the function
33
describe the parts of a function call
write the function name and parentheses next to it. pass an argument to it?
34
what are the differences between a function call and a function definition?
calling a function means executing it.
35
what is the difference between a parameter and an argument?
Parameter is variable in the declaration of function. | Argument is the actual value of this variable that gets passed to function.
36
why are function parameters useful?
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?
37
what two effects does a return statement have on the behavior of a function?
The return statement ends function execution and specifies a value to be returned to the function caller
38
why do we log things to the console.?
to see the result value and for debugging
39
what is the method?
method is a function which is a property of an object
40
how is a method different from any other function?
function themselves are objects, so, in that context, a method is actually an object reference to a function.
41
How do you remove the last element from an array?
use the pop() method.
42
how do you round a number down to the nearest integer?
Math.floor() bring it down to the nearest integer.
43
how do you generate a random number?
Math.random()
44
How do you delete an element from an array?
splice(start, deleteCount, item1)
45
how do you append an element to an array?
push()
46
how do you break a string up into an array?
split()
47
do string methods change the original string? how would you check if you weren't sure?
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.
48
roughly how many string methods are there according to the MDN web docs?
45-50 methods.
49
is the return value of a function or method useful in every situation?
sometimes. push() method is just to add an element to the array
50
roughly how many array methods are there according to the MDN web docs?
many many
51
what three letter acronym should you always include in your google search about a javascript method or css property?
MDN
52
Give six examples of comparison operators.
, ===, ==, >=, <=, !==
53
what data type do comparison expressions evaluate to?
boolean, true or false
54
what is the purpose of an 'if' statement?
to declare a condition within the function
55
Is 'else' required in order to use an 'if' statement?
not always.
56
describe the syntax of an 'if' statement
if (condition) { | }
57
what are the three logical operators?
and / or / not
58
how do you compare two different expressions in the same condition?
adding add (&&) or OR (||) with two conditions
59
what is the purpose of a loop?
Loops are used in JavaScript to perform repeated tasks based on a condition.
60
what is the purpose of a condition expression in a loop?
Conditional statements control behavior in JavaScript and determine whether or not pieces of code can run
61
what does "iteration" mean in the context of loops?
a step where some action is repeated
62
when does the condition expression of a 'while' loop get evaluated?
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
when does the initialization expression of a for loop get evaluated?
start point of the loop.
64
when does the condition expression of a for loop get evaluated?
after the initializtion and the condition
65
when does the final expression of a for loop get evaluate?
after the code block is done and after the next condition is executed?
66
Besides the return statement, which exits its entire function block?
break;
67
what does the ++ increment operator do?
adds number one, re-assigns and substitutes in its value.
68
how do you iterate through the keys of an object?
use the 'for in ' loops
69
what event is fired when a user places their cursor in a form control?
focus
70
what event is fired when a user's cursor leaves a form control?
blur
71
what event is fired as a user changes the value of a form control?
input
72
what event is fired when a user clicks the "submit" button within a ?
submit event
73
what does the event.preventDefault() method do?
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
what property of a form element object contains all of the form's controls.
elements property
75
what property of a form control object gets and sets its value?
value property
76
what is one risk of writing a lot of code without checking to see if it works so far?
hard to debug
77
what is an advantage of having your console open when writing a JavaScript program?
you can check the values one at a time.
78
what is the event.target?
the element that triggered the event
79
What is the affect of setting an element to display: none?
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
What does the element.matches() method take as an argument and what does it return?
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
How can you retrieve the value of an element's attribute?
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
At what steps of the solution would it be helpful to log things to the console?
all steps for the solution
83
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?
Individually apply each event handlers for each element
84
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?
we would have to add each if statement for every element
85
what is JSON?
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
what are serialization and deserialization ?
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
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
88
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
89
why are serialization and deserialization useful?
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
How do you store data in 'localStorage'?
localStorage.setItem(key, value);
91
How do you retrieve data from localStorage?
localStorage.getItem(key)
92
what data type can 'localStorage' save in the browser?
string type
93
when does the 'beforeunload' event fire on the window object?
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
what is a method?
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
How can you tell the difference between a method definition and a method call?
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
Describe method definition syntax (structure).
``` var something = { add: function(x, y) { return result } } ```
97
Describe method call syntax(structure)
something.add()
98
How is a method different from any other function?
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
what are the four principles of OOP?
Abstraction, Encapsulation, Inheritance, Polymorphism
100
what is the defining characterisitic of OOP?
objects can contain both data (as properties) and behavior (as methods).
101
What is abstraction?
being able to work with complex things in simple ways
102
what does API stand for?
Application Programming Interface(API)
103
what is the purpose of an API?
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
what is 'this' in javascript?
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
what does it mean to say that this is an "implicit parameter"?
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
'when' is the value of 'this' determined in a function?
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
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); } }; ```
character variable -> no. becuz its not being called. -> so its nothing. (parameters do not have a value, it doesn't exist)
108
Given the above character object, what is the result of the following code snippet? Why? character.greet();
the greeting message. "Its me, mario" - why? | becuz we're calling the greet method of the character object
109
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
undefined. window does not have a firstName property.
110
How can you tell what the value of this will be for a particular function or method definition?
you cant. there's no way cuz its not being used yet.
111
How can you tell what the value of this is for a particular function or method call?
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
What kind of inheritance does the JavaScript programming language use?
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
what is a prototype in JavaScript?
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
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?
make a prototype and set the prototype to the object.
115
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
proto
116
what does the 'new' operator do?
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
what property of JavaScript functions can store shared behavior for instances created with new?
prototype property
118
what does the 'instanceof' operator do?
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
what is a callback function?
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
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?
setTimeout()
121
How can you set up a function to be called repeatedly without using a loop?
setInterval() function
122
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
value of zero meaning immediately.
123
What do setTimeout() and setInterval() return?
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
what is ajax?
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
what does the AJAX acronym stand for?
Asynchronous JavaScript And XML.
126
which object is built into the browser for making HTTP requests in javascript?
XMLHttpRequest()
127
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
128
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
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
What is Array.prototype.filter useful for?
Array.prototype.filter() The filter() method creates a new array with all elements that pass the test implemented by the provided function.
130
What is Array.prototype.map useful for?
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
What is Array.prototype.reduce useful for?
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
What must the return value of myFunction be if the following expression is possible? myFunction()();
function
133
``` What does this code do? const wrap = value => () => value; ```
returns value function
134
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
when it's defined (lexical scope)
135
What allows JavaScript functions to "remember" values from their surroundings?
closures