JavaScript Flashcards

1
Q

What is the purpose of variables?

A

It is to store bits of information 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

You have to use a variable keyword like ‘var’ and then follow it with a variable name. From there, you use the assignment operator ‘=’ and assign a value to it

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

[variable name] = [variable 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 must begin with a letter, dollar sign, or an underscore
Can contain letters, numbers, dollar signs, or underscores

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

Score and Score would be different values

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

Used for working with any kind of text

Frequently used for adding new content to a page

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

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

Serves as an on/off switch

Helpful in determining which part of the script should run

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 operator

Gives value to something

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

To update you would re-assign a value to the variable

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.

Every Object is derived from null value, and therefore typeof operator returns object for it:

undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.

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

So that there is context to the output

Helps with debugging

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

Give five examples of JavaScript primitives.

A

data that is not an object and has no methods. There are 7 primitive data types: string, number,, boolean, undefined,, and null.

We can disregard bigInt and symbol for the time being

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

The process of joining together two or more strings to create one new string

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

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 then re-assigns 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

They are used for storing different variables and values of different data types

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

What are object properties?

A

A variable that is in an object.

Individual key in an object that correlates with a value

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

Describe object literal notation.

A

Create a variable and assign it to a value with curly braces. In the curly braces have names that indicate properties or methods and assign them value by using a colon

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

To delete a property, you use the keyword delete and then use the dot notation to identify the property or method you want to remove from the object

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 using square brackets

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

What are arrays used for?

A

When working with a list or a set of values related to each other
Especially helpful when you do not know how many items a list will contain
Representing lists of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
Var array = []
26
How are arrays different from "plain" objects?
Each value in the array doesnt need a variable name/key All arrays come with length property Other ways to add to an array compared to plain objects
27
What number represents the first index of an array?
array[0]
28
What is the length property of an array?
Array.length gives you the length of an array.
29
How do you calculate the last index of an array?
Take the length and subtract by 1, then use that as an index
30
What is a function in JavaScript?
Functions are a special kind of object that is "callable". A function is a code that you can re-use packing up code for reuse throughout a program giving a name to a handful of code statements to make it code easier to read making code "dynamic", meaning that it can be written once to handle many (or even infinite!) situations
31
Describe the parts of a function definition.
The function keyword to begin the creation of a new function. An optional name. (Our function's name is sayHello.) A comma-separated list of zero or more parameters, surrounded by () parentheses. (Our sayHello function doesn't have any parameters.) The start of the function's code block, as indicated by an { opening curly brace. An optional return statement. (Our sayHello function doesn't have a return statement.) The end of the function's code block, as indicated by a } closing curly brace.
32
Describe the parts of a function call.
simply writing the name of the function and placing () parentheses next to it. The function's name. Again, our function's name is sayHello. A comma-separated list of zero or more arguments surrounded by () parentheses. Our sayHello function does not take any arguments.
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call uses the already defined function by including the function name and parentheses. In parentheses there might be arguments. Function definition first states that it is a function by using function keyword, then defines the function name, sets up parameters (optional), followed by curly braces, inside the curly braces is code block. Calling function gives an output while defining a function does not
34
What is the difference between a parameter and an argument?
Parameter as a placeholder. A variable whose value is not known until we call the function and pass in an argument Parameters are declared when we define the function Arguments When we call a function, we pass in the arguments Is the actual name of what the placeholder was
35
Why are function parameters useful?
They serve as a placeholder, they tell you what kind of value will be need to be placed there when calling the function Give us the ability to have varying results based on the arguments we give
36
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we can use in our program. Prevents any more code in the function's code block from being run.
37
What is an expression?
A chunk of code that needs to be evaluated to lead to a value
38
Why do we log things to the console?
console.log() | Debugging mechanism to understand what output we are getting
39
What is a method?
A method is a function which is a property of an object.
40
How is a method different from any other function?
It is a function that is stored in a property of an object
41
How do you remove the last element from an array?
array.pop()
42
How do you round a number down to the nearest integer?
Math.floor()
43
How do you generate a random number?
Math.random()
44
How do you delete an element from an array?
array.splice(index,0)
45
How do you append an element to an array?
array.push()
46
How do you break a string up into an array?
array.split()
47
Do string methods change the original string? How would you check if you weren't sure?
No, you would check by console logging the original string variable
48
Roughly how many string methods are there according to the MDN Web docs?
50 - ish
49
Is the return value of a function or method useful in every situation?
no
50
Roughly how many array methods are there according to the MDN Web docs?
40
51
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
52
Give 6 examples of comparison operators.
``` === !== >< <= >= ```
53
What data type do comparison expressions evaluate to?
boolean
54
What is the purpose of an if statement?
The if statement evaluates a condition. If the condition evaluates true, and statements in the subsequent code block are executed. Lets you run different behavior based on data Allow us to have different pathways in our code
55
Is else required in order to use an if statement?
no
56
Describe the syntax (structure) of an if statement.\
If (score >= 50) { congratulate(); } If keyword, condition, opening curly brace, code block, closing curly brace
57
What are the three logical operators?
&& - and || - or ! - not
58
How do you compare two different expressions in the same condition?
You would use logical operators. | So two expressions and logical operators
59
What is the purpose of a loop?
It allows us to run a code for a specified number of times
60
What is the purpose of a condition expression in a loop?
It checks a condition and stops the code once the condition was met
61
What does "iteration" mean in the context of loops?
An iteration is when the code is looped over
62
When does the condition expression of a while loop get evaluated?
The beginning / before each iteration of the loop
63
When does the initialization expression of a for loop get evaluated?
At the very beginning and doesnt happen again
64
When does the condition expression of a for loop get evaluated?
After the initialization. Before each iteration of the loop
65
When does the final expression of a for loop get evaluated?
After the code block runs. At the end of the iteration. Right before the condition runs.
66
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
67
What does the ++ increment operator do?
It adds one to the variable and re-assigns
68
How do you iterate through the keys of an object?
``` For in loops const object = { a: 1, b: 2, c: 3 }; ``` for (const property in object) { console.log(`${property}: ${object[property]}`); }
69
What is JSON?
JavaScript Object Notation as standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications JSON is a text-based data format following JavaScript object syntax JSON exists as a string — useful when you want to transmit data across a network. It needs to be converted to a native JavaScript object when you want to access the data.
70
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 disk or send it over the network. Deserialization is the reverse process: turning a stream of bytes into an object in memory.
71
Why are serialization and deserialization useful?
Useful for sending over data and using the data and save to hard drive
72
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify(array object)
73
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse(string)
74
How to you store data in localStorage?
localStorage.setItem(key, value)
75
How to you retrieve data from localStorage?
localStorage.getItem(‘key’)
76
What data type can localStorage save in the browser?
JSON string
77
When does the 'beforeunload' event fire on the window object?
Before the page reloads
78
What is a method?
A method is a function which is a property of an object.
79
How can you tell the difference between a method definition and a method call?
Method definition has a code block with opening and closing brackets and says the word ‘function’ A method call does not have neither of the two
80
Describe method definition syntax (structure).
Value (method name) first then a colon ‘:’ after the colon is the function definition, possible parameters and the function code block
81
Describe method call syntax (structure).
The Name of the object dot the name of the method and parentheses with arguments inside if needed
82
How is a method different from any other function?
A method is within the object. Any other function is not in an object
83
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods).
84
What are the four "principles" of Object-Oriented Programming?
Abstraction Encapsulation Inheritance Polymorphism
85
What is "abstraction"?
being able to work with (possibly) complex things in simple ways Abstraction in computer programming is a way to reduce complexity and allow efficient design and implementation in complex software systems. It hides the technical complexity of systems behind simpler APIs. What something does without needing to know how it does it
86
What does API stand for?
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software
87
What is the purpose of an API?
One purpose of APIs is to hide the internal details of how a system works, exposing only those parts a programmer will find useful and keeping them consistent even if the internal details later change Software abstraction
88
What is this in JavaScript?
it's an implicit parameter, of all JS functions This is the variable that holds the object that the function is working with
89
What does it mean to say that this is an "implicit parameter"?
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. Explicit means you have to name it to use use it. This doesn't need to be defined to use
90
When is the value of this determined in a function; call time or definition time?
Call time
91
How can you tell what the value of this will be for a particular function or method definition?
You can’t tell because it isn't being used yet
92
How can you tell what the value of this is for a particular function or method call?
Whenever you are dealing with this it needs to be being called and the value of this is whatever is being called. Essentially to the left of the dot
93
What kind of inheritance does the JavaScript programming language use?
Prototype based inheritance or prototypal
94
What is a prototype in JavaScript?
An object that other objects are able to build upon
95
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?
It uses a prototype
96
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
It checks to see if it has a prototype
97
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. Creates a blank, plain JavaScript object. Adds a property to the new object (__proto__) that links to the constructor function's prototype object Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step). Returns this if the function doesn't return an object.
98
What property of JavaScript functions can store shared behavior for instances created with new?
.prototype
99
What does the instanceof operator do?
Returns a boolean if an object is an instance of another object
100
.prototype is in constructor function and __proto__ is in the new instance
.prototype is in constructor function and __proto__ is in the new instance
101
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.
102
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()
103
How can you set up a function to be called repeatedly without using a loop?
setInterval()
104
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
No delay
105
What do setTimeout() and setInterval() return?
The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.