JavaScript Flashcards

1
Q

What is the purpose of variables?

A

A placeholder (container) to temporarily store bits of information/data in memory.

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 a variable keyword (const, let, var) and then assign it a variable name.

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

Use the assignment operator (=).

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

-Variables must only start with a letter, dollar sign ($), or and underscore ().
-Variables can contain letters, numbers, dollar sign ($), or an underscore(
).
DO NOT USE a dash (-) or a period (.) in a variable name.
-Variables CANNOT use keywords or reserved words.

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 Score and score would be different variables, but it is bad practice to create two variables that have the same name using different cases.

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

Storing and manipulating text data.

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

Storing and manipulating numerical data (maths).

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 logical data type that can have only the values true or false.
(Booleans allow for making decisions in JavaScript).

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.

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

Reassign it.

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

Undefined is a variable that refers to something that doesn’t exist, and the variable isn’t defined to be anything. (Accidental emptiness).
-Programmers will NEVER use undefined as a variable.

Null is a variable that is defined but is missing a value. (Purposeful emptiness).
-Programmers will sometimes use null as a variable.

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

-Make things more clear.
-To help debug.

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

Give seven 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 are objects used for?

A

To store multiple pieces of data, that are related to each other.

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

What are objects properties?

A

A individual piece of named data that stores a value, within an object.

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

Describe object literal notation.

A

An object literal with key: value pairs is assigned to a variable.

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

What are the two ways to get or update the value of a property?

A

Dot notation.
Square bracket notation.

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

What are arrays used for?

A

-Organizing data.

-Working with a list or a set of values
that are related to each other.

-Especially helpful when you do not
know how many items a list will contain.

-Storing a list of information, either order is very important or not important.

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

Describe array literal notation.

A
  • Give the array a name. (Make a variable).

-Values are then assigned to the array inside a pair of square brackets, and each value is separated by a comma.

-(Array values do not need to be the same data type, but often are).

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

How are arrays different from “plain” objects?

A

*** Arrays always start with a length (index 0).

  • Arrays are a special type of object. They hold a related set of key/value pairs (like all objects), but the key for each value is its index number.

-Arrays have index numbers for keys.

-Arrays, almost always, contain the same data type.

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

What number represents the first index of an array?

A

Zero.

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

What is the length property of an array?

A

-The length property sets or returns the number of elements in an array.

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

How do you calculate the last index of an array?

A

-Example: array.length - 1.

24
Q

What is a function in JavaScript?

A

A set of actions/instructions that can be reused in the code.

25
Q

Describe the parts of a function definition.

A
  • Function keyword.
  • name of function (optional).
  • Zero or more parameters.
  • Code block.
  • Code within code block.
  • Return (optional).
  • End of code block.
26
Q

Describe the parts of a function call.

A
  • Function name.
  • Arguments.
27
Q

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

A
  • A function definition has a keyword and a code block, function calls do not.
28
Q

What is the difference between a parameter and an argument?

A
  • Parameters are used as placeholders for variables in the function definition.
  • Arguments are used to input data to the function definition, in the function call.
29
Q

Why are function parameters useful?

A
  • They hold variables (placeholders), which can be used to input data types.
  • Makes functions reusable for different data inputs.
  • Gives functions variance.
30
Q

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

A
  • It returns the result of the function definition to the function call.
  • It can stop the function.
31
Q

Why do we log thins to the console?

A
  • To test/verify code.
  • To bug check.
32
Q

What is a method?

A

A method is a function that is assigned to a property within an object.

33
Q

How is a method different from any other function?

A

It is a function within an object.

** Dot notation is used when a method is called. ***

34
Q

How do you remove the last element from an array?

A

Use the .pop() method.

35
Q

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

A

Use the Math.floor() method.

36
Q

How do you generate a random number?

A

Use the Math.random() method.

37
Q

How do you delete an element from an array?

A

Use the .splice() method.

38
Q

How do you break a string up into an array?

A

Use the .split() method.

39
Q

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

A

Strings are immutable, so it does not change the string stored in memory.

You can console log the string variable.

Check the MDN documentation.

40
Q

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

A

No, sometimes it’s not.

Ex. You would never save the return value of console.log.

41
Q

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

A

MDN

42
Q

Give 6 examples of comparison operators.

A

Strickly equal to ( === )
Strickly not equal to ( !== )
Greater than ( > )
Less than ( < )
Greater than or equal to ( >= )
Less than or equal to ( <= )

43
Q

What data type do comparison expressions evaluate to?

A

Data type: Boolean (true or false).

44
Q

What is the purpose of an ‘if’ statement?

A

Allows for decision making in code.
Creates branching logical paths.

45
Q

Describe the syntax (structure) of an ‘if’ statement.

A
  • ‘If” keyword.
  • Condition(s) within parentheses.
  • Conditional code block for the return.
46
Q

What are the three logical operators?

A
  • Logical ‘And’ (&&).
  • Logical ‘Or’ ( || ).
  • Not operator ( ! ).
47
Q

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

A

Use a logical operator. ( && / || )

48
Q

What is the purpose of a loop?

A

-A tool that allows you do to something over and over again.

  • Repeatable job.
  • Similar to an assembly line.
49
Q

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

A
  • Creates the condition to end the loop.
  • Exit the loop, when the condition is no longer true.
  • Allows the loop to keep going, but does not increment the loop.
50
Q

What does ‘iteration’ mean in the context of loop?

A
  • Repeatable.
51
Q

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

A
  • Before each iteration of the code block.
52
Q

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

A
  • ONCE, before anything else.
53
Q

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

A
  • Before each iteration.
54
Q

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

A
  • After each iteration. (And before the condition).
55
Q

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

A
  • Break.
56
Q

What does the ++ increment operator do?

A
  • Increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.
57
Q

How do you iterate through the keys of an object?

A
  • Use a ‘for…in’ loop.