JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Storing values

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 the var 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

Var x = 89;

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

Underscores, $. Numbers 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

The uppercase or lowercase letter refers to 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

To store or manipulate text letters and sentences

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 and manipulate numbers and 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

True or false for conditionals, loops

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 to a 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

Use the variable name and the equal sign and assign the value

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 an intentional no value, and undefined is not intentional

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

For clarity to understanding what the console is working on, 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

String numbers 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, numbers

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

What is string concatenation?

A

adding 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

Add numbers and concatenating strings

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

adding to the value of the variables

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

What are objects used for?

A

Containers for keeping information

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

What are object properties?

A

The keys that give information about the object

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

[] or dot notation

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 multiple items

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

Describe array literal notation.

A

[] separated by “,”

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

it can be indexed by numbers starting from 0

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

calculate the size of the 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

length -1

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

What is a function in JavaScript?

A

A process that can be used and called to perform that same process.

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

Describe the parts of a function definition.

A

The name of the function, the function keyword, parameter list., code block, return statement.

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

Describe the parts of a function call.

A

Name of the function () arguments in the parenthesis.

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

A

Function calls require actual values, while function definitions require a name or variables, 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 the name that is given o the piece of data that will give, later on, arguments are the actual values that are being passed on to the function.

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

Why are function parameters useful?

A

To be empty conatainers to hold values for the upcoming 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 makes the value of the function a value that is not undefined.

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

Debugging and for clarity.

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

What is a method?

A

A function that is being stored as a property.

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

How is a method different from any other function?

A

A method must be attached and be called upon an object.

40
Q

How do you remove the last element from an array?

A

array.pop()

41
Q

How do you round a number down to the nearest integer?

A

Math.floor()

42
Q

How do you generate a random number?

A

Math.random() within the range of 0-1 non-inclusive

43
Q

How do you delete an element from an array?

A

array.shift()-> from the begining;array.pop -> from the end; array.splice() froman arbitrary point till any point.

44
Q

How do you append an element to an array?

A

srting.push()

45
Q

How do you break a string up into an array?

A

string.split()

46
Q

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

A

No, because strings are immutable-> log console and mdn.

47
Q

Roughly how many string methods are there according to the MDN Web docs?

A

A lot.

48
Q

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

A

No,

49
Q

Roughly how many array methods are there according to the MDN Web docs?

A

A lot

50
Q

What three-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

boolean (true or false)

53
Q

What is the purpose of an if statement?

A

Change the flow of the code, and make decisions.

54
Q

Is else required in order to use an if statement?

A

No

55
Q

Describe the syntax (structure) of an if statement.

A

If (condition){}

56
Q

What are the three logical operators?

A

logical and, or, not

57
Q

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

A

&& or/and ||

58
Q

What is the purpose of a loop?

A

To allow to do something multiple times

59
Q

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

A

To put a stop to the loop

60
Q

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

A

Running of the for loop code block

61
Q

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

A

Beginning and after each iteration

62
Q

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

A

In the beginning, and it only happens one time

63
Q

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

A

Before each iteration

64
Q

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

A

After the code block

65
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

66
Q

What does the ++ increment operator do?

A

Increments the counter variable

67
Q

How do you iterate through the keys of an object?

A

For in loop

68
Q

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

A

focus

69
Q

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

A

blur

70
Q

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

A

input

71
Q

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

A

submit

72
Q

What does the event.preventDefault() method do?

A

prevent the default state from occurring

73
Q

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

A

delete the data

74
Q

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

A

.elements property

75
Q

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

A

value property

76
Q

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

A

the code could be broken but you wouldn’t know where.

77
Q

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

A

visualize code and variables

78
Q

What is a method?

A

A function of the object

79
Q

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

A

the function definition() block and call: name of the object. method name ().

80
Q

Describe method definition syntax (structure).

A

Methods are functions attached to object,

81
Q

Describe a method call syntax (structure).

A

object.methodname(arguments).

82
Q

How is a method different from any other function?

A

that it acts on the object

83
Q

What is the defining characteristic of Object-Oriented Programming?

A

Objects contain data and behavior.

84
Q

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

A

encapsulation, polymorphism, abstraction, inheritance

85
Q

What is “abstraction”?

A

hiding irrelevant information

86
Q

What does API stand for?

A

application programming interface

87
Q

What is the purpose of an API?

A

allows the application to access data to communicate to the user and vice versa

88
Q

What is* this* in JavaScript?

A

Object that the function is acting on

89
Q

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

A

it is actaully named and typed out

90
Q

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

A

Call time

91
Q
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);
  }
};
A

Nothing at this point

92
Q

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

A

It’s a me Mario!

93
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

It’s a-me undefined

94
Q

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

A

You can’t, as it hasn’t been called yet.

95
Q

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

A

Object to the left of the dot.