JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store variable data in short-term memory. They can be used to represent values in scripts that are likely to change

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

How do you declare a variable?

A

By using a variable keyword(var, let, const) followed by the variable name(identifier)

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

By using the assignment operator (=) after the variable name followed by the variable value you want to assign to the variable

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

Names can contain letters, numbers, dollar sign ($), or an underscore (), but may only begin with a letter, dollar sign ($), or and underscore ()

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

It means that it would recognize the two names “variable” and “Variable” as different names

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

Strings contain letters and other characters and can be used when working with any kind of text. They’re frequently used to add new content into a page and they can contain HTML markup

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

Numbers are for numerical values, including negative numbers and decimals, and are also used for tasks like calculators, determining the size of the screen, moving the position of an element on a a page, or setting the amount of time an element should take to fade in

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

a boolean can only hold two values: true or false and are helpful when determining which part of a script should run

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

The equals (=) sign is an assignment operator. It says that you are going to assign a value to the variable. It is also used to update the value given to a variable

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

The assignment operator can also be used to update the value given to a variable

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

a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address while undefined is a value automatically assign to variables that have only been declared, or to formal arguments for which there are no actual arguments. Though they are both marked as one of the primitive values, when using the typeof operator, null returns “object”

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

By including a short string that describes the variable or value being logged, it is helpful when debugging

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, undefined, null, bigint, symbol

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

“Adding” strings together, one following the other in order

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

What purpose(s) does the + operator serve in javascript?

A

The + operator serves as both the arithmetic operator for addition of numbers as well as for adding strings with 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 (true or false)

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 += operator adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible

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

What are objects used for?

A

Objects group together a set of variables and functions to create a model of a something you would recognize from the real world

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

What are object properties?

A

An object property is a variable part of an object which tell us more 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

Object literal notation is the easiest and most popular way to create objects where you define an object with a curly braces assigned to a variable

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

Remove a property from an object using the “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

dot notation (object.property) and bracket notation (object[‘property’])

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

What are arrays used for?

A

Arrays are for storing a list or a set of values that are related to each other

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

Describe array literal notation.

A

It is the preferred method for creating an array when you create an array and give it a name using the var keyword followed by the name of the array and then assign the values to the array inside a pair of square brackets with each value separated by a comma

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 indexed starting at 0 and objects have named keys for properties

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 (array[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

.length (array.length)

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[array.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 function is a “power” tool that is useful for packing up code for reuse throughout a program, giving a name to a handful of code statements to make the code easier to read, and making code “dynamic” in that it can be written once to handle many (or even infinite!) situations

31
Q

Describe the parts of a function definition.

A
  1. The function keyword to begin the creation of a new function.
  2. An optional name
  3. A comma-separated list of zero or more parameters, surroundded by () parentheses
  4. The start of the function’s code block, as indicated by an { opening curly brace
  5. An optional return statement
  6. The end of the function’s code block, as indicated by a } closing curly brace
32
Q

Describe the parts of a function call.

A

Simply write the name of the function and placing () parentheses next to it as well as any arguments inside the parentheses

33
Q

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

A
34
Q

What is the difference between a parameter and an argument?

A

When defining a function, parameters are declared and that when calling a function, arguments are passed to it

35
Q

Why are function parameters useful?

A

When the function’s code block is run, the parameter is will be holding the value of the argument

36
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 the program
  2. Prevents any more code in the function’s code block from being run
37
Q

Why do we log things to the console?

A

To make sure values are what we expect them to be at different parts of the code

38
Q

What is a method?

A

A method is a function which is a property of an object. There are two kinds of methods: instance methods which are built-in tasks performed by an object instance, or static methods which are tasks that are called directly on an object constructor

39
Q

How is a method different from any other function?

A

It is a function that is specifically a property of an object

40
Q

How do you remove the last element from an array?

A

By using the .pop() method

41
Q

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

A

By using the Math.Floor() static method

42
Q

How do you generate a random number?

A

By using the Math.random() static method which returns a pseudo-random number that’s greater than or equal to 0 and less than 1

43
Q

How do you delete an element from an array?

A

By using the .pop() method, the .shift() method, or the .splice() method

44
Q

How do you append an element to an array?

A

By using the .push() method or the .unshift() method

45
Q

How do you break a string up into an array?

A

By using the .split() method

46
Q

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

A

String methods do not change the original string because strings are immutable. If you weren’t sure, you would console.log() the original strings after calling the string methods

47
Q

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

A

~50

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

~40

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

53
Q

What is the purpose of an if statement?

A

To evaluate or check a condition to see if the statements in the subsequent code block will be executed

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
  1. keyword if
  2. condition in parentheses ()
  3. code to execute if value is true (condition is met) enclosed in curly braces
56
Q

What are the three logical operators?

A

&&, ||, !

57
Q

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

A

By having an extra set of parentheses () around each expression

58
Q

What is the purpose of a loop?

A

Loops will run a code block as long as the condition they’re checking for is true. They allow you to repeat a process over and over without having to write the same instructions each time you want a program to perform a task

59
Q

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

A

The condition is what tells the loop to either keep running or to stop. If the condition returns true, the code block will run. If the condition returns false, the loop will stop

60
Q

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

A

Iteration means one walkthrough of the code inside the loop

61
Q

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

A

At the very beginning of each iteration

62
Q

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

A

At the very beginning of the first iteration

63
Q

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

A

After the condition check has returned true

64
Q

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

A

After each iteration

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

The “break” keyword

66
Q

What does the ++ increment operator do?

A

It increments whatever is on the left by 1 and updates it with the new value

67
Q

How do you iterate through the keys of an object?

A

By using a for. . . in loop with [x]

68
Q

In JavaScript, when is scope determined?

A
69
Q

What allows JavaScript functions to “remember” values from their surroundings?

A
70
Q

What values does a closure contain?

A
71
Q

When is a closure created?

A
72
Q

How can you tell if a function will be created as a closure?

A
73
Q

In React, what is one important case where you need to know if a closure was created?

A