JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To use as an identifier in JavaScript and the variable must be identified with unique names.

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 var, let (variable with restricted scope), or const (a variable that can’t be reassigned) 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

Put = operator. var a = 1.

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 first character must start with a letter, underscore, or a dollar sign ($), and don’t forget variable names are case-sensitive and don’t use JavaScript’s reserved keywords.

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

This means that any identifiers should always be typed with consistent character capitalization within acceptable rules.

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

It is used for storing and manipulating text in JavaScript.

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

It is a primitive wrapper object used to represent and manipulate numbers.

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

It is used to represent one of two values in a value, such as True or False, Yes or No, and On or Off.

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

It performs some operation on single or multiple operands (data values) and produces a result.

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

Just update the new value under the same variable name or use temporary values.

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

They are equal in value but different in type.

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 identify easier, faster, and more directly when you work on some big project or work with coworkers.

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, number, boolean, null, and undefined. Everything else is an object.

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

It returns by numerical values.

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

What is string concatenation?

A

It is the process of appending one string to the end of another 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

It produces the sum of numeric operands or 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

It returns a boolean value.

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

It is a standalone entity that holds multiple values in terms of properties and methods.

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

What are object properties?

A

It’s a variable that is attached to the object. It is sorted as the same as an ordinary variable except for the attachment to the object.

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

Describe object literal notation.

A

var object name = {property name: value of it, another property name: value of it}.

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

Use keyword delete the object name.property name or keyword delete object name[‘property name’].

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 name.property name = value that you want to update or object name[‘property name’] = value that you want to update.

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

What are arrays used for?

A

It is used when you store a collection of variables of the same type.

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

Describe array literal notation.

A

var array object name = [‘’, ‘’, ‘’ ];

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

Objects represent a special data type that is mutable and can be used to store a collection of data. On the other hand, arrays are a special type of variable that is also mutable and can also be used to store a list of values.

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

The length property sets or returns the number of elements in that 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

the length of the array - 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

It is a code to perform a particular task or calculate a value.

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

keyword function, name of the function, parameter, but it should take some input and return output and there is some obvious relationship between them

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

Keyword function and give the name of the function and put parenthesis (give parameter or not). You should define the function in the scope from which you wish to call it.

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

A function definition’s meaning is to remember the method of it but stays still. On the other hand, a function call instructs JavaScript to execute the code of the function.

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

The parameters are listed inside of the parenthesis. The arguments are the values received by the function when it is invoked.

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

Why are function parameters useful?

A

Because those are expected to be the same as variables except that the values of these variables are defined when we call the function.

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 ends the execution of a function and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.

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

It prints the output to the console, so we can see what is going on, and be able to fix the code if something is wrong.

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

What is a method?

A

It is a function that 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 any other function?

A

A method is a function that belongs to an object.

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

Use array pop() method. name of array.pop();

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

Use Math.floor() function.

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

Use Math.random() function.

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

Use splice() method, pop() method, or shift() method (removes the first array).

44
Q

How do you append an element to an array?

A

Use unshift() method to add a new element at the beginning, push() method to add a new element at the end, or name of array[index number].

45
Q

How do you break a string up into an array?

A

Use the split(‘ ‘) method.

46
Q

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

A

No. Use console.log() to check.

47
Q

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

A

split(), split([separator[, limit]]),

48
Q

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

A

38 methods on there.

49
Q

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

A

MDN

50
Q

Give 6 examples of comparison operators.

A

Strict equal to (===), greater than (>), greater than or equal to (>=), less than or equal to (<=), less than (

51
Q

What data type do comparison expressions evaluate to?

A

Boolean

52
Q

What is the purpose of an if statement?

A

To perform different actions based on different conditions. Use if statement to specify a code to be executed if a specified condition is true.

53
Q

Is else required in order to use an if statement?

A

No, it’s not required to write the else part for the if statement.

54
Q

Describe the syntax (structure) of an if statement.

A

Keyword if (variable name, comparison, value) { }.

55
Q

What are the three logical operators?

A

And (&&), or (||), not (!).

56
Q

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

A

Using logical and or or operators.

57
Q

What is the purpose of a loop?

A

It used to repeatedly run a block of code until a certain condition is met.

58
Q

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

A

It is an expression that is evaluated once before every iteration.

59
Q

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

A

It describes going through a set of operations that deal with the code conditions.

60
Q

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

A

When the while loop is created.

61
Q

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

A

When the loop is created.

62
Q

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

A

Right after the initialization.

63
Q

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

A

at the end of each loop iteration.

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

65
Q

What does the ++ increment operator do?

A

Added 1 to the value of the variable.

66
Q

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

A

Focus.

67
Q

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

A

Blur.

68
Q

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

A

Input.

69
Q

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

A

Submit.

70
Q

What does the event.preventDefault() method do?

A

Its default action should not be taken as it normally would be.

71
Q

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

A

Refresh the page and refresh.

72
Q

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

A

Elements.

73
Q

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

A

Value property.

74
Q

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

A

Hard to debug when an error occurs.

75
Q

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

A

Checking and debugging very easily.

76
Q

What is the event.target?

A

The target property of the event interface is a reference to the object onto which the event was dispatched.

77
Q

What is the affect of setting an element to display: none?

A

It makes it invisible and it takes off from the document.

78
Q

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

A

It returns a boolean if the value of the CSS selector and the element is matched.

79
Q

At what steps of the solution would it be helpful to log things to the console?

A

Whenever I set up the new variable or after creating a loop or condition.

80
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

I have to write so many conditional statements. So much work has to do.

81
Q

What is a method?

A

It’s a function that is a property of an object.

82
Q

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

A

The instance methods are built-in tasks performed by an object instance. The static methods are tasks that are called directly on an object constructor.

83
Q

Describe method definition syntax (structure).

A

Put property name: function definition with parameter and opening curly brace for the function code block.

84
Q

Describe method call syntax (structure).

A

Put property name of the object name and put values in parentheses.

85
Q

How is a method different from any other function?

A

A method is associated with an object, but a function is not.

86
Q

What is the defining characteristic of Object-Oriented Programming?

A

It’s a programming paradigm based on the concept of objects that can contain data and code.

87
Q

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

A

Abstraction, Encapsulation, Inheritance, Polymorphism.

88
Q

What is “abstraction”?

A

It’s one of the key concepts of OOP. The main goal is to handle complexity by hiding unnecessary details from the user.

89
Q

What does API stand for?

A

It’s the acronym Application Programming Interface, which is a software intermediary that allows two applications to talk to each other.

90
Q

What is the purpose of an API?

A

It simplifies programming by abstracting the underlying implementation and only exposing objects or actions the developer needs.

91
Q

What is “this” in JavaScript?

A

This refers to the object it belongs to, but it has different values depending on where it is used. This refers to the owner object in a method, but This refers to the global object in a function.

92
Q

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

A

Because This keyword is available in a function’s code block even though it was never included in the function’s parameter or declared as a variable.

93
Q

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

A

The value of this is determined at call time.

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

This refers to the variable character.

95
Q

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

A

It will get the value of the variable message because that is a value of the greet property of the character object.

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

It will get an error because there is no function named hello is exist.

97
Q

What kind of inheritance does the JavaScript programming language use?

A

It uses prototypal inheritance.

98
Q

What is a prototype in JavaScript?

A

It’s a mechanism that JavaScript objects inherit features from one another.

99
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

Because of the prototype chain. It explains why different objects have properties and methods defined on other objects available to them.

100
Q

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

A

Look it up to the proto objects.

101
Q

What does the “new” operator do?

A

It creates a new object and adds a property to the new object (__proto__) that links to the constructor function’s prototype object. Bind the newly created object instance as “this” context. Return “this” if the function doesn’t return an object.

102
Q

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

A

The prototype property.

103
Q

What does the “instanceof” operator do?

A

It determines whether the prototype property of the constructor exists somewhere in the prototype chain of the object.

104
Q

What is a “callback” function?

A

It’s a function passed into another function as an argument. It used to be invoked inside the outer function to complete some other action.

105
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() method.

106
Q

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

A

0.

107
Q

What do setTimeout() and setInterval() return?

A

It returns a number of IDs.