JavaScript Flashcards

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
Q

describe array literal notation

A

variable then bracket index values end with comma 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

Arrays are listed in an order, individually named, set length will repair themselves if an index is deleteds

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

array.length gives the total amount of index in an 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

array.length - 1

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

What is a function?

A

A repeatable chunk of code with a specific purpose

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

Describe parts of a function definition

A

function keyword and name then parameters then curly braces then code inside

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

Describe parts of the function call

A

function name parentheses argument semi colon

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 function definition?

A

Definition has a code block and function keyword

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 placeholders for arguments that doesn’t have a value that is known. Used when defining thefunction while arugments are used when calling

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

Why are function parameters useful?

A

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

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

It causes the function to produce a value we can use in our program and prevents anymore code from running.

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 test debugging and inspect if our code works

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

What is a method?

A

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 other functions

A

they are properties of objects

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

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

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

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

pop()

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

push method

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

how do you break a string into an array?

A

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?

A

They do not and console.log the original string and go to MDN

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 docs?

A

a lot

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

sometimes but not all the time

49
Q

How many array methods are there?

A

A lot

50
Q

What 3 letter acronym should you always include in your google search about a javascript method or CSS property?

A

MDN

51
Q

give 6 examples of comparison operators?

A

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

52
Q

What data type do comparison expressions evaluate to?

A

Booleans

53
Q

What is the purpose of an if statement?

A

It evaluates if a condition is true then runs the code block

54
Q

is else required in order to use an if statement?

A

no

55
Q

Describe the syntax of an if statement?

A

if keyword condition curly braces for code

56
Q

what are the 3 logical operators?

A

&& || !

57
Q

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

A

logical or/ and operator

58
Q

What is the purpose of a loop?

A

to check conditions/do something over and over again til its false

59
Q

What is the purpose of a condition?

A

its how many iterations the loop will run depending on if its true or false

60
Q

What does iteration mean in the context of loops?

A

A cycle of the for loop/ every time the code block runs

61
Q

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

A

at the beginning of the loop

62
Q

When does the initialization of a for loop get evaluated

A

at the beginning

63
Q

when does the condition get evaluated?

A

after the initialization

64
Q

When does the final expression get evaluted?

A

After the code block has run

65
Q

besides a return, which exits its function, which keyword exits a loop before its condition?

A

The break

66
Q

What does the ++ increment operator do?

A

it adds one to the variable

67
Q

How do you iterate through the keys of an object?

A

with a for in loop

68
Q

What is JSON?

A

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

Why are serialization and deserialization useful?

A

You can send objects over a network and it can be parsed by the receiver

71
Q

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

A

JSON.stringify();

72
Q

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

A

JSON.parse()

73
Q

how do you store data in localStorage?

A

setItem();

74
Q

How do you retrieve data from localStorage?

A

getItem();

75
Q

What data type can localstorage save in the browser?

A

string data

76
Q

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

A

When the document and its resources are about to be unloaded.

77
Q

What is a method?

A

A function which is stored in a property of an object

78
Q

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

A

definition has function keyword curly braces and code to run inside the code block.

79
Q

Describe method definition syntax

A

method name with an anonymous function and the opening curly brace for the method code block and code to be run.

80
Q

describe method call syntax

A

Method call has the method of the object being called with parentheses

81
Q

How is a method difference from any other function?

A

Its used on objects, that object may include other methods and general data. Methods can use all the other tools inside the object.

82
Q

What is the defining characteristic of OOP

A

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

83
Q

What are the four principles of OOP

A

abstraction, encapsulation, polymorphism, inheritance

84
Q

what is abstraction?

A

Being able to work with possibly complex things in simple ways.

85
Q

What does API stand for?

A

Applied programming interface

86
Q

What is the purpose of API?

A

to give programmers a way to interact with a system in simplified, consistent fashion: aka abstraction

87
Q

What is this in JavaScript?

A

An implicit parameter

88
Q

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

A

Its available in the function code block even tho it was never included in the functions parameters.

89
Q

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

A

call time

90
Q
What doesthisrefer to in the following code snippet?var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
}
A

nothing its a trick question

91
Q

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


A

a function returning its a me Mario

92
Q

Given the abovecharacterobject, what is the result of the following code snippet? Why?

A

its a/me undefined. becaues there is no firstName in the function call.

93
Q

How can you tell what the value ofthiswill be for a particular function or methoddefinition?

A

you can’t cause its not defined

94
Q

How can you tell what the value ofthisis for a particular function or methodcall?

A

if its to the left of the dot and if there is no object then its the window global object.

95
Q

What kind of inheritance does the javascript programming language use?

A

prototypal inheritance

96
Q

What is a prototype in JavaScript?

A

A JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects.

97
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

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
Q

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

A

within the proto object.

99
Q

waht does the new operator do?

A

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
Q

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

A

prototype property

101
Q

What does the instanceof operator do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

102
Q

What is a “callback” function?

A

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

104
Q

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

A

setInterval()

105
Q

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

A

0

106
Q

What do setTimeout() and setInterval() return?

A

A positive integer value which identifies the timer created by the call.

107
Q

What is a client?

A

a piece of computer hardware or software that accesses a service made by a server. reqeusts something.

108
Q

what is a server?

A

a piece of computer hardware or software that provides functionality for other programs or devices called clients.

109
Q

Which http method does a browser issue to a web server when you visit a URL?

A

GET

110
Q

what three things are on the start-line of an HTTP request message?

A

An HTTP method, the request target, and the http version.

111
Q

What three things are on the start-line of an HTTP response message?

A

protocol version status code and status text.

112
Q

What are HTTP headers?

A

a case sensitive string followed by a colon and a value who’s structure depends upon the head. additional information

113
Q

Where would you go if you wanted to learn more about a specific HTTP header

A

MDN?

114
Q

Is a body required for a valid HTTP request or response message?

A

no

115
Q

What is a code block? what are some examples of a code block?

A

its where the code runs if the condition is true. If else, for, do while, while try catch

116
Q

What does block scope mean?

A

Anything within the curly braces

117
Q

What is the scope of a variable declared with const or let?

A

block scope

118
Q

What is the difference between let and const?

A

let variables can have value reassigned but the variable itself cannot be redclared to another name?