JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data/ information that the script will 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

var, let, const

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

var variableName = value;

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

What rules are allowed in naming variable names?

A

must begin with letter, $, or _ and must NOT start with a number
can contain characters above but not - or .
cannot use existing keywords like var
case sensitive
camel case

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 != Score

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 include text data such as names… etc characters

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 numerical data, integers…. decimals..

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 logical data, true false, 1 and 0,

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, assigns value to variables

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 recalling the variable name and assigning with a new value after the first assignment line

var number = 1;
number = 2;
console.log(number)
>2

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

difference is that null is derived from an object and points to non-existent/ invalid object
undefined is a value assigned to variables that have not been assigned a value

null says the there is no box in existence, undefined says the box is empty

null is assigned to be empty on purpose –> “empty”

never assign anything with undefined

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 specify what the varible the input is coming from

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

Give five examples of JavaScript primitives.

A

number string 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

number

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

What is string concatenation?

A

combining string values using + arithmetic operator

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

addition operator and string concatenation

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

addition assignment, adds left side to value to variable current value.

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

What are objects used for?

A

objects are used to provide properties or characteristics to one ‘object’

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

What are object properties?

A

variables of that object that describe a value

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

Describe object literal notation.

A

{ property: value, …. }

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 object.property

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
object.property = new value
object['property'] = new value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are arrays used for?

A

to store a list of items or objects

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

Describe array literal notation.

A

[value, value, value]

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

ordered, the property of arrays is its index

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?

How do you calculate the last index of an array?

A

array.length gives length of array

array[array.length - 1]

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

What is a function in JavaScript?

A

a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output

allow you to package up code for use later in your program

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

Describe the parts of a function definition.

Describe the parts of a function call.

A

function functionName (parameters) { code block }

functionName(argument)

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

call does not have code blocks just an argument

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

What is the difference between a parameter and an argument?

A

when defining a function you call parameters but when you call a function you define arguments.

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

Why are function parameters useful?

A

because it is like a placeholder until a variable is passed through an argument and the function is called

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

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

A

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.

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

Why do we log things to the console?

A

to print value of a variable to the console and is used as sa debuggin tool

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

What is a method?

A

a function that is a property of an object

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

How is a method different from any other function?

A

it is a property that comes from that object/array constructor so that any object/array created will have that method used

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

How do you remove the last element from an array?

A

array.pop()

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

How do you delete an element from an array?

A

array.splice( start_index, how_many_removed, replace_values … )

42
Q

How do you append an element to an array?

A

array.push( )

43
Q

How do you break a string up into an array?

A

array.split( string that you want to separate the values with )

’’ -> each character
‘ ‘ -> space
‘, ‘ -> comma

44
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

no, call the variable to the console

45
Q

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

A

no, sometimes you just need to remove elements in an array for example

46
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

mdn lol

47
Q

Give 6 examples of comparison operators.

A

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

48
Q

What data type do comparison expressions evaluate to?

A

boolean

49
Q

What is the purpose of an if statement?

Is else required in order to use an if statement?

A

for conditional logic in code

no

50
Q

Describe the syntax (structure) of an if statement.

A

if ( conditional ) {code block } else if ( conditional) {code block} else {code block}

51
Q

What are the three logical operators?

A

< > =

52
Q

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

A

&& ||

53
Q

What is the purpose of a loop?

A

to repeat a set of instruction to a different data point

54
Q

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

A

to specify how much to iterate the code block

55
Q

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

A

how many times the code block will be run

56
Q

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

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

When does the final expression of a for loop get evaluated?

A

before an iteration happens once

before an iteration

after an iteration

57
Q

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

A

before an iteration

58
Q

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break

59
Q

What does the ++ increment operator do?

How do you iterate through the keys of an object?

A

adds one to the variable

for (key in object)

60
Q

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

A

.getAttribute( html class name )

61
Q

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

A

a css selector and returns a boolean

62
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

Write a lot more eventlisteners

63
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

If conditionals

64
Q

What is JSON?

A

Javascript string object notation. it

65
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 disk or send it over the network.

Deserialization is the reverse process: turning a stream of bytes into an object in memory.

66
Q

Why are serialization and deserialization useful?

A

can take something like json and be able to go from human language to machine data language and reverse

67
Q

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

A

JSON.stringify( )

68
Q

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

A

JSON.parse( )

69
Q

How to you store data in localStorage?

A

localStorage.setItem(‘keyValue’ , ‘value’)

70
Q

How to you retrieve data from localStorage?

A

localStorage.getItem(‘keyValue’)

returns valiue of the key value pair

71
Q

What data type can localStorage save in the browser?

A

JSON

72
Q

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

A

when you refresh and “unload” data

73
Q

What is a method?

Describe method definition syntax (structure).

Describe method call syntax (structure).

A

function that is a property of an object

object = {
method: function () { }
}

object.method(arguments

74
Q

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

A

method definition is making the method as a property of an object and method call is using dot notation to call on the method

75
Q

How is a method different from any other function?

A

it is a property of an object

76
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

77
Q

What are the four “principles” of Object-Oriented Programming?

A

Abstraction:
Anytime you see a simple interface covering a more complex system

Encapsulation:
Inheritance
Polymorphism

78
Q

What does API stand for?

What is the purpose of an API?

A

application programming interface (API)

connects computers or software to each other

79
Q

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

A

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

80
Q

What is this in JavaScript?

A

implicit parameter of function where it is being called from

81
Q

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

A

call time

82
Q

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

A

cant tell bc –> this is not defined yet

83
Q

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

A

object to left of dot when method is called

and window in function

84
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype based inheritnANCE

85
Q

What is a prototype in JavaScript?

A

a model in which something is patterened, in terms of javascript a prototype includes inherited properties / methods

86
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

because all of those are prototypes of string objects array objects numbers objects that is already preset in JavaScript

87
Q

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

A

the prototype

88
Q

What does the new operator do?

A

creates a new ‘object’ or whatever typeof based on the constructor that comes after it. It includes all prorotype properties and methods

  1. Creates a blank, plain JavaScript object.
  2. Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
  3. 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).
  4. Returns this if the function doesn’t return an object.
89
Q

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

A

.prototype

90
Q

What does the instanceof operator do?

A

checks to see if an object is part of a prototype chain of a constructor. returns a boolean if it is or isn’t

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

92
Q

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

A

setInterval( some function to be run, time interval)

93
Q

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

A

0ms

returns a intervalID that 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.

94
Q

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

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

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

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

A

focus

blur

input

submit

95
Q

What does the event.preventDefault() method do?

A

If put inside function it prevents it from doing what is supposed to happen happen

96
Q

What does submitting a form without event.preventDefault() do?

A

reloads the page with the form’s values in the URL?

97
Q

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

A

.elements

98
Q

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

A

form.elements.namevalue.value

99
Q

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

A

will run into errors

100
Q

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

A

see where error occurs in line of code