Javascript Flashcards

(68 cards)

1
Q

What are arrays used for?

A

Storing lists, especially lists of ordered or related data.

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

Describe array literal notation.

A

Comma-delineated items between square brackets.

[ item1, item2 . . . ]

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

How are arrays different from “plain” objects?

A

The keys in arrays are numbers instead of strings; Arrays are numerically indexed.

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

What is the length property of an array?

A

The number of items in the array.

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

How do you calculate the last index of an array?

A

arrayLength - 1

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

What are objects used for?

A

They group together related information (ie. variables and functions)

In OOP (object oriented programming) objects are used to model areal-world objects.

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

What are object properties?

A

Key-value pairs consisting of a property and its value.

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

Describe object literal notation.

A

Comma-delineated key-value pairs between curly braces.

{ prop1: val1, prop2: val2, . . . }

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

How do you remove a property from an object?

A

The delete operator.

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

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

A

Dot notation (using member operator) and bracket notation

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

What is string concatenation?

A

Joining strings together

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

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

A

Adding numbers and concatenating strings

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

What does the += “plus-equals” operator do

A

It is shorthand for performing addition or concatenation and then assigning the result to the variable on the left.

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

What is the purpose of variables?

A

Temporarily store pieces of data while a program is running.

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

How do you declare a variable?

A

Using the keyword const, let, or var followed by the variable name

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

How do you initialize (assign a value to) a variable?

A
using the assignment operator (=)
var varName = aValue;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What characters are allowed in variable names?

A

Letters, numbers, $, and _ (underscore). Variables names cannot start with a number.

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

What does it mean to say that variable names are “case sensitive”?

A

Lower and upper case letters are considered different characters.

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

What is the purpose of a string?

A

Store and represent text date/characters

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

What is the purpose of a number?

A

Represent/store numeric data so you can do math/arithmetic.

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

What is the purpose of a boolean?

A

To represent/store binary data which lets you do logic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the difference between null and undefined?
Undefined means ‘no value given yet’; null explicitly means ‘nothing’ or ‘intentional absence’
26
Why is it a good habit to include "labels" when you log values to the browser console?
Helps with debugging since a label can indicate where and what variable a value comes from.
27
Give five examples of JavaScript primitives
string, number, boolean, undefined, null, ...symbol is also a type
28
What is a function in JavaScript?
A named, reusable block of code that performs a task. Functions can accept inputs and return outputs
29
Describe the parts of a function definition.
1. The function keyword 2. optional function name 3. list of 0 or more parameters, 4. code block surrounded by curly braces, 5. optional return statement inside the code block
30
Describe the parts of a function call.
1. Function name | 2. pair of parentheses, containing arguments
31
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition contains the function keyword and a code block, function call does not have these
32
What is the difference between a parameter and an argument?
Parameters appear in the function definition. Arguments are the actual input values a function is called with.
33
Why are function parameters useful?
Parameters let you pass inputs into a function for it to use
34
What two effects does a return statement have on the behavior of a function?
1. causes the function to stop running/exits the function.A return statement also 2. causes the function to produce a value/output that can then be used by the rest of your program
35
Why do we log things to the console?
To know what your data looks like; Logging to console lets you check the value of a variable at a specific place/time in the running of the code
36
What is a method?
A method is a function which is a property of an object.
37
How is a method different from any other function?
A method is part of/associated with an object. A function is not.
38
How do you remove the last element from an array?
array.pop() method
39
How do you round a number down to the nearest integer?
Math.floor()
40
How do you generate a random number?
Math.random() method
41
How do you delete an element from an array?
Array.splice() method
42
How do you append an element to an array?
Array.push()
43
How do you break a string up into an array?
String.split()
44
Do string methods change the original string? How would you check if you weren't sure?
No, because strings are immutable. Log to console or check MDN to check yourself.
45
Is the return value of a function or method useful in every situation?
No. Just because a function returns a value doesn't mean you have to use it.
46
What is the purpose of a loop?
Repeating a block of code a set number of times.
47
What is the purpose of a condition expression in a loop?
Checks if it’s time for the loop to stop
48
What does "iteration" mean in the context of loops?
A single run of the code in the loop’s code block
49
When does the condition expression of a while loop get evaluated?
Before each iteration of the while-loop.
50
When does the initialization expression of a for loop get evaluated?
Once before the loop begins any iterations
51
When does the condition expression of a for loop get evaluated?
Before the first iteration and then before each subsequent iteration of the for-loop.
52
When does the final expression of a for loop get evaluated?
After the completion of each iteration
53
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Keyword ' break '
54
What does the ++ increment operator do?
It is the shorthand equivalent to +=1
55
How do you iterate through the keys of an object?
for...in loop
56
Give 6 examples of comparison operators.
>, =, <=, === (strictly equal), == (loosely equal)
57
What data type do comparison expressions evaluate to?
boolean
58
What is the purpose of an if statement?
Lets your code do different things based on the result of a comparison
59
Is else required in order to use an if statement?
no
60
Describe the syntax (structure) of an if statement.
if keyword , condition, if-block, optional else-block
61
What are the three logical operators?
&& (and), || (or), ! (not)
62
How do you compare two different expressions in the same condition?
Using && operator or || operator (or the ! versions)
63
What is a "callback" function?
A function that is passed as an argument into another function. The function it’s passed into calls it later to perform some task
64
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?
The setTimeout() method
65
How can you set up a function to be called repeatedly without using a loop?
The setInterval() method
66
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
Default delay is 0 (ms), meaning as soon as possible; The delay you set is the minimum amount of time elapsed before callback is run
67
What do setTimeout() and setInterval() return?
A timer id. Use this id in clearTimeout() or clearInterval() to cancel timeout or interval
68
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
When it is defined