JavaScript Flashcards

(118 cards)

1
Q

what is the purpose of a variable?

A

variables store a value of something

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

how do you declare a variable?

A

use the keyword var then the name of the variable

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

You’d use the assignment operator

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

underscore dollar sign and letters

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

If its not case sensitive then they are 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

A series of characters in a row. Data that is not code.

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

Calculations

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 represent logic values

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

what does the = operator mean in JS

A

the assignment operator

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

set the value to the right of the assignment operator

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

Null is a placeholder and undefined is javascript way of saying empty

They both mean empty, lack of value datatypes. Undefined is under the control of javascript. Null has to be assigned by an assignment operator. Somewhere down the line of history a human being came down and assigned null.

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

It’ll give us a point of reference.

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

Give five examples of JavaScript primitives.

A

Strings, boolean, undefined, numbers, 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

a number

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

What is string concatenation?

A

adds numbers and concatenates 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 serve in JavaScript?

A

its the addition operator

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

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

The addition assignment operator (+=) 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

to create a model of something you would recognize in the real world. All stored together in one area

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

What are object properties

A

They tell us about the object, variables that live inside an object.

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

Describe object literal

A

the object name curly braces and key value pairs

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 operator

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

What are two ways to get or update the value of a property?

A

dot and 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/groups of similar data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
describe array literal notation
variable then bracket index values end with comma brackets
26
how are arrays different from "plain" objects
Arrays are listed in an order, individually named, set length will repair themselves if an index is deleteds
27
What number represents the first index of an array
0
28
What is the length property of an array?
array.length gives the total amount of index in an array
29
How do you calculate the last index of an array
array.length - 1
30
What is a function?
A repeatable chunk of code with a specific purpose
31
Describe parts of a function definition
function keyword and name then parameters then curly braces then code inside
32
Describe parts of the function call
function name parentheses argument semi colon
33
When comparing them side by side, what are the differences between a function call and function definition?
Definition has a code block and function keyword
34
What is the difference between a parameter and an argument?
Parameters are placeholders for arguments that doesn't have a value that is known. Used when defining thefunction while arugments are used when calling
35
Why are function parameters useful?
They are placeholders for the arguments. If there were no parameters the behavior would always be the same. It gives us the ability to allow our behavior to act based on a certain set of values
36
What two effects does a return statement have on the behavior of a function?
It causes the function to produce a value we can use in our program and prevents anymore code from running.
37
Why do we log things to the console?
to test debugging and inspect if our code works
38
What is a method?
a function which is a property of an object
39
How is a method different from other functions
they are properties of objects
40
How do you remove the last element from an array?
pop method
41
How do you round a number down to the nearest integer?
Math.floor()
42
How do you generate a random number?
Math.Random()
43
How do you delete an element from an array?
pop()
44
how do you append an element to an array?
push method
45
how do you break a string into an array?
split method
46
Do string methods change the original string?
They do not and console.log the original string and go to MDN
47
roughly how many string methods are there according to the MDN docs?
a lot
48
Is the return value of a function or method useful in every situation?
sometimes but not all the time
49
How many array methods are there?
A lot
50
What 3 letter acronym should you always include in your google search about a javascript method or CSS property?
MDN
51
give 6 examples of comparison operators?
< > <= >= !== ===
52
What data type do comparison expressions evaluate to?
Booleans
53
What is the purpose of an if statement?
It evaluates if a condition is true then runs the code block
54
is else required in order to use an if statement?
no
55
Describe the syntax of an if statement?
if keyword condition curly braces for code
56
what are the 3 logical operators?
&& || !
57
how do you compare two different expressions in the same condition?
logical or/ and operator
58
What is the purpose of a loop?
to check conditions/do something over and over again til its false
59
What is the purpose of a condition?
its how many iterations the loop will run depending on if its true or false
60
What does iteration mean in the context of loops?
A cycle of the for loop/ every time the code block runs
61
When does the condition expression of a while loop get evaluated?
at the beginning of the loop
62
When does the initialization of a for loop get evaluated
at the beginning
63
when does the condition get evaluated?
after the initialization
64
When does the final expression get evaluted?
After the code block has run
65
besides a return, which exits its function, which keyword exits a loop before its condition?
The break
66
What does the ++ increment operator do?
it adds one to the variable
67
How do you iterate through the keys of an object?
with a for in loop
68
What is JSON?
Javascript object notation. a format we can represent data in most commonly used to send data across a network. Syntax is that of a javascript object.
69
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can store it or send it over a network. Deserialization is the opposite where you turn the stream of bytes into an object in memory. Spread out over a system so ease of access and ease of storage
70
Why are serialization and deserialization useful?
You can send objects over a network and it can be parsed by the receiver
71
How do you serialize a data structure into a JSON string using javascript?
JSON.stringify();
72
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
73
how do you store data in localStorage?
setItem();
74
How do you retrieve data from localStorage?
getItem();
75
What data type can localstorage save in the browser?
string data
76
When does the 'beforeunload' event fire on the window object?
When the document and its resources are about to be unloaded.
77
What is a method?
A function which is stored in a property of an object
78
How can you tell the difference between a method definition and method call
definition has function keyword curly braces and code to run inside the code block.
79
Describe method definition syntax
method name with an anonymous function and the opening curly brace for the method code block and code to be run.
80
describe method call syntax
Method call has the method of the object being called with parentheses
81
How is a method difference from any other function?
Its used on objects, that object may include other methods and general data. Methods can use all the other tools inside the object.
82
What is the defining characteristic of OOP
objects can contain both data (as properties) and behavior (as methods)
83
What are the four principles of OOP
abstraction, encapsulation, polymorphism, inheritance
84
what is abstraction?
Being able to work with possibly complex things in simple ways.
85
What does API stand for?
Applied programming interface
86
What is the purpose of API?
to give programmers a way to interact with a system in simplified, consistent fashion: aka abstraction
87
What is this in JavaScript?
An implicit parameter
88
what does it mean to say that this is an implicit parameter?
Its available in the function code block even tho it was never included in the functions parameters.
89
When is the value of this determined in a function; call or definition time?
call time
90
``` 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); } } ```
nothing its a trick question
91
Given the above character object, what is the result of the following code snippet? Why?character.greet();

a function returning its a me Mario
92
Given the above character object, what is the result of the following code snippet? Why?
its a/me undefined. becaues there is no firstName in the function call.
93
How can you tell what the value of this will be for a particular function or method definition?
you can't cause its not defined
94
How can you tell what the value of this is for a particular function or method call?
if its to the left of the dot and if there is no object then its the window global object.
95
What kind of inheritance does the javascript programming language use?
prototypal inheritance
96
What is a prototype in JavaScript?
A JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects.
97
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?
Its placed in a prototype object and then the ojbects will delegate to take that object when they aren't able to perform the required task themselves.
98
if an object does not have it's own property or method by a given key, where does javascript look for it?
within the _proto_ object.
99
waht does the new operator do?
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.
100
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
101
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
102
What is a "callback" function?
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.
103
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()
104
How can you set up a function to be called repeatedly without using a loop?
setInterval()
105
What is the default time if you omit the delay parameter from setTimeout() or setInterval()?
0
106
What do setTimeout() and setInterval() return?
A positive integer value which identifies the timer created by the call.
107
What is a client?
a piece of computer hardware or software that accesses a service made by a server. reqeusts something.
108
what is a server?
a piece of computer hardware or software that provides functionality for other programs or devices called clients.
109
Which http method does a browser issue to a web server when you visit a URL?
GET
110
what three things are on the start-line of an HTTP request message?
An HTTP method, the request target, and the http version.
111
What three things are on the start-line of an HTTP response message?
protocol version status code and status text.
112
What are HTTP headers?
a case sensitive string followed by a colon and a value who's structure depends upon the head. additional information
113
Where would you go if you wanted to learn more about a specific HTTP header
MDN?
114
Is a body required for a valid HTTP request or response message?
no
115
What is a code block? what are some examples of a code block?
its where the code runs if the condition is true. If else, for, do while, while try catch
116
What does block scope mean?
Anything within the curly braces
117
What is the scope of a variable declared with const or let?
block scope
118
What is the difference between let and const?
let variables can have value reassigned but the variable itself cannot be redclared to another name?