JavaScript Flashcards

1
Q

What are objects used for?

A

Objects are used to group together a set of variables and functions.

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

What are object properties?

A

Object properties are just variables, but in objects.

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

What is object literal notation?

A

Object literal notation is an array of key + value pairs within a curly brace; a colon separates the keys and values and a comma separates every key + value pair.

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

How do you remove a property from an object?

A

To remove a property from an object, you use the delete operator.

Example: delete pet.name or delete pet[name].

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

What are functions in objects called?

A

Methods.

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

How would you read the below?

var student = {
firstName: 'Luke',
lastName: 'Skywalker',
age: 25
};
A

“There is an object literal being assigned to the variable ‘student’ with the string ‘Luke’ being assigned to the firstName property, the string ‘Skywalker’ being assigned to the lastName property, and the number 25 being assigned to the age property.”

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

What are arrays used for?

A

Arrays are used to store lists of values.

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

How do you grab the first index of an array?

A

We use the number 0 since it represents the first index of an array.

Example: 
var chargersPlayers = ['Keenan', 'Herbert', 'Derwin', 'Bosa']
console.log(chargersPlayers[0]);
//expected output: Keenan
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the length property of an array?

A

It’s a property that’s used to return the number of elements within that array.

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

How do we calculate the last index of an array?

A

We subtract 1 from the length of the array.

Example:
var top5BasketballPlayers = [‘MJ’, ‘Kobe’, ‘LeBron’, ‘Steph’, ‘KD’];
var lastIndex = top5BasketballPlayers.length - 1;
console.log(top5BasketballPlayers[lastIndex]);
//expected output: KD

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

What is a function in JavaScript?

A

A JavaScript function is a block of code designed to perform a particular task.

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

What are the 6 parts of a function definition?

A
  1. function keyword
  2. name (optional)
  3. parameters (optional)
  4. start of the function’s code block
  5. return statement (optional)
  6. end of the function’s code block
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you call a function?

A

To call a function, we use the parentheses following the function’s name.

Ex. getName( )

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

What is the difference between defining a function and calling a function?

A

When defining a function, we’re just creating the functionality of the function itself. Calling the function means that we’re actually running the function (with the parameters if there are any).

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

What is the difference between a parameter and an argument?

A

Function parameters are the names listed in the function’s definition. Function arguments are the real values passed to the function.

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

Why are function parameters useful?

A

Parameters are useful to functions, because otherwise you can’t give the function-machine an input.

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

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

A
  1. Causes the function to produce a value we can use in our program.
  2. 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
18
Q

How should you go about naming your functions?

A

When it comes to naming functions, the name should summarize the code block. A good rule is to make sure your function’s name includes at least a verb. A verb-noun combination is best.

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

How would you read the following?

function convertMinutesToSeconds(minutes) {
   var seconds = minutes * 60;
   return seconds;
}
A

“There is a function definition named convertMinutesToSeconds with a single parameter named minutes followed by an opening curly brace for the code block. The variable minutes is being multiplied by 60 and the result of that expression is being assigned to the variable seconds. The value of the variable is being return from the function.”

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

What is a expression in JavaScript?

A

An expression is a line of code that produces a value.

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

How would you read the following?

var convertMinutesToSecondsResult = convertMinutesToSeconds(5);

A

“The convertMinutesToSeconds is being called with one argument of 5 and the return of that function being assigned to the variable convertMinutesToSeconds.”

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

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

A

a method definition is usually within an object specifically assigned to a parameter whereas a method call has the object followed by a period/dot and the method name with optional parameters.

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

How is a method different from any other function?

A

it serves the same purpose except a method lives within an object

25
Q

What is thedefining characteristicof Object-Oriented Programming?

A

it’s based on the concept of objects with data as properties and behaviors as methods

26
Q

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

A

abstraction, encapsulation, inheritance & polymorphism

27
Q

What is “abstraction”?

A

abstraction is the removal of details to focus on more important details aka filtering out things - generalizes something with out going in on the details so the user can execute complex behavior without needing to know details

28
Q

What does API stand for?

A

application programming interface

29
Q

What is the purpose of an API?

A

allows two applications to talk to each other; allowing software to be easily used without users needing to understand the mechanisms behind the software

30
Q

What is encapsulation?

A

the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an object’s components - it’s used to hide the values or state of a data object inside a class, preventing direct access to them by clients in a way that could expose hidden implementation details

31
Q

What is inheritance?

A

mechanism of basing an object or class upon another object or class - n other words, deriving new classes (or subclasses) from existing ones such as a super class or base class and then forming them into a hierarchy of classes

32
Q

What is polymorphism?

A

the provision of a single interface to entities of different types or the use of a single symbol to represent multiple different types

33
Q

What is’this’in JavaScript?

A

an implicit parameter of all JavaScript functions; it essentially refers to an object that is executing the current piece of code

34
Q

What does it mean to say thatthisis an “implicit parameter”?

A

it’s available in the function’s code block even though it wasn’t declared or was in the parameter

35
Q

Whenis the value ofthisdetermined in a function;call timeordefinition time?

A

call time

36
Q

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

A

you don’t because it’s not being called/invoked.

37
Q

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

A

by looking at the object on the left of the dot

38
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based

39
Q

What is a prototype in JavaScript?

A

an object that contains properties and (predominantly) methods that can be used by other objects.

40
Q

What does the filter( ) method do?

A

Creates a new array with all elements that pass the test implemented by the provided function.

Can only be used on arrays.

41
Q

How does the filter ( ) method work?

A

It loops through each element of an array and checks each element against the predicate. If it’s true, it’ll push the element into a new array. Otherwise, it’ll move on to the next element.

42
Q

What are the 7 falsy values?

A

false, 0, undefined, null, NaN, 0n, ‘ ‘

43
Q

How do you make a shallow copy of an array?

A

the splice( ) method

44
Q

How do create a shallow copy of an object?

A

Object.assign( { } , obj)

45
Q

What happens when you create a new variable (x) and assign it to the value of another variable (y)?

A

The new variable’s value is assigned a reference to the value of the original variable (x). It’s important to note that when you modify the new variable (y), the original variable (x) will be modified as well since they’re references/aliases.

46
Q

What does the map( ) method do?

A

The map( ) method creates a new array populated with each element transformed from the provided function.

47
Q

What is a JavaScript Promise?

A

It’s a proxy for a value not necessarily known when the promise is created.

48
Q

A Promise is usually in one of 3 states—what are the 3 states and what do they mean?

A
  • pending: initial state, neither fulfilled nor rejected.
  • fulfilled: meaning that the operation was completed successfully.
  • rejected: meaning that the operation failed.
49
Q

How do you create a new Promise?

A
new Promise( (resolve, reject) => {
...
}
50
Q

What does block scope mean?

A

Block scope essentially means that a variable inside a specific block can’t be accessed by the outside of the block.

51
Q

What is the difference betweenletandconst?

A

You can’t reassign the value of the variable when using const.

52
Q

Why is it possible to.push()a new value into aconstvariable that points to anArray?

A

You’re allowed to mutate the value that was originally assigned to the variable—you just can’t reassign the variable.

53
Q

What is template literal notation and what are the benefits of it?

A

It’s another way of working with strings but with back ticks.

The benefits of this include:

  • we can have multiple lines in the string without using ‘\n’
  • string interpolation
  • HTML escaping
54
Q

What is string interpolation and how do you do it?

A

The ability to substitute part of the string for the values of variables or expressions.

You do it by placing the variable or expression in a special block/case as follow - ${variable_name}

55
Q

What is HTML escaping and when do you use it?

A

The ability to transform a string so that it’s safe to include in HTML,

56
Q

What is procedural programming?

A

Procedural programming loosely means that we declare variables to hold the state of our applications and defined functions to update those variables. Most beginners learn to code through procedural programming.

57
Q

What does the ‘new’ operator do?

A

Thenewoperatorlets developers create an instance of a user-defined object type aka creates a new Javascript object, array, functions, etc.

58
Q

When it comes to constructor functions, how should variables be named?

A

You should always use a capital letter to indicate that it’s a constructor function.

59
Q

What does the instanceof operator do?

A

Theinstanceofoperatortests to see if theprototypeproperty of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.