Javascript Flashcards

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
Q

What is the difference between null and undefined?

A

Undefined means ‘no value given yet’; null explicitly means ‘nothing’ or ‘intentional absence’

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

Helps with debugging since a label can indicate where and what variable a value comes from.

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

Give five examples of JavaScript primitives

A

string, number, boolean, undefined, null, …symbol is also a type

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

What is a function in JavaScript?

A

A named, reusable block of code that performs a task. Functions can accept inputs and return outputs

29
Q

Describe the parts of a function definition.

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

Describe the parts of a function call.

A
  1. Function name

2. pair of parentheses, containing arguments

31
Q

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

A

A function definition contains the function keyword and a code block, function call does not have these

32
Q

What is the difference between a parameter and an argument?

A

Parameters appear in the function definition. Arguments are the actual input values a function is called with.

33
Q

Why are function parameters useful?

A

Parameters let you pass inputs into a function for it to use

34
Q

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

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

Why do we log things to the console?

A

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
Q

What is a method?

A

A method is a function which is a property of an object.

37
Q

How is a method different from any other function?

A

A method is part of/associated with an object. A function is not.

38
Q

How do you remove the last element from an array?

A

array.pop() method

39
Q

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

A

Math.floor()

40
Q

How do you generate a random number?

A

Math.random() method

41
Q

How do you delete an element from an array?

A

Array.splice() method

42
Q

How do you append an element to an array?

A

Array.push()

43
Q

How do you break a string up into an array?

A

String.split()

44
Q

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

A

No, because strings are immutable.

Log to console or check MDN to check yourself.

45
Q

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

A

No. Just because a function returns a value doesn’t mean you have to use it.

46
Q

What is the purpose of a loop?

A

Repeating a block of code a set number of times.

47
Q

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

A

Checks if it’s time for the loop to stop

48
Q

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

A

A single run of the code in the loop’s code block

49
Q

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

A

Before each iteration of the while-loop.

50
Q

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

A

Once before the loop begins any iterations

51
Q

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

A

Before the first iteration and then before each subsequent iteration of the for-loop.

52
Q

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

A

After the completion of each iteration

53
Q

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

A

Keyword ‘ break ‘

54
Q

What does the ++ increment operator do?

A

It is the shorthand equivalent to +=1

55
Q

How do you iterate through the keys of an object?

A

for…in loop

56
Q

Give 6 examples of comparison operators.

A

> , =, <=, === (strictly equal), == (loosely equal)

57
Q

What data type do comparison expressions evaluate to?

A

boolean

58
Q

What is the purpose of an if statement?

A

Lets your code do different things based on the result of a comparison

59
Q

Is else required in order to use an if statement?

A

no

60
Q

Describe the syntax (structure) of an if statement.

A

if keyword , condition, if-block, optional else-block

61
Q

What are the three logical operators?

A

&& (and), || (or), ! (not)

62
Q

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

A

Using && operator or || operator (or the ! versions)

63
Q

What is a “callback” function?

A

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

The setTimeout() method

65
Q

How can you set up a function to be called repeatedly without using a loop?

A

The setInterval() method

66
Q

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

A

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
Q

What do setTimeout() and setInterval() return?

A

A timer id.

Use this id in clearTimeout() or clearInterval() to cancel timeout or interval

68
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

When it is defined