Javascript Flashcards

1
Q

What is the purpose of variables?

A

Used to hold data for scripting

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 the keyword var then the name you want to give to the variable

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

with the “=” sign.

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

letters, numbers, _, $

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

var Apple is different then var apple

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 hold information in text form.

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 hold information in numerical form.
Used for math

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

to declare if something is true or false. Used for conditionals
Allow us to make decisions in code.

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

Is being assigned to

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

write the name of the variable with a different value

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

null is purposeful emptiness. (declared by developer)
undefined is accidental emptiness. (declared by javascript)

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

Helps with 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, null, undefined

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

To join 2 or more strings together.

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

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

A

can be used for arithmetic expressions and also string 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

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

adds the value and assigns that result to original value.
ex: x+=y // x = x + y

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

What are objects used for?

A

to store data with multiple properties(pieces of data) in a variable.

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

What are object properties?

A

individual piece of named data within an object.

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

Describe object literal notation.

A

declare the variable name it, “{
and key: value,
key: value,
};
object, key, value

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

use the delete keyword followed by the object name and property name
delete object.property;

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

object.property = ‘updated value’
object[‘property’] = ‘updated value’
dot notation and square bracket notation.

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

What are arrays used for?

A

It is used to store a list of information/values.

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

Describe array literal notation.

A

array = [ ‘one’, ‘two’, ‘three’];

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

Values of an array are almost always the exact same data type.
Has a length property as default.

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]

28
Q

What is the length property of an array?

A

shows total number of values are in the array.

29
Q

How do you calculate the last index of an array?

A

array.length - 1

30
Q

What is a function in JavaScript?

A

A process or set of actions with a name that can be reused within your code.

31
Q

Describe the parts of a function definition.

A

(function keyword) ->function nameOfFunction(parameter) {
function block
ends with return statement
};

32
Q

Describe the parts of a function call.

A

nameOfFunction(argument); <– argument is optional depending.

33
Q

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

A

function definitions include a function keyword and code block.

34
Q

What is the difference between a parameter and an argument?

A

parameter is used as a placeholder to define function, argument is the actual value used when you call it.

35
Q

Why are function parameters useful?

A

It gives you the ability to apply the function to many different things without writing a different function.

36
Q

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

A
  1. return causes the function to produce a value.
  2. Prevents any more code in the function code block from running.
37
Q

Why do we log things to the console?

A

To help with troubleshooting, to check your code.

38
Q

What is a method?

A

It is a function stored as a property of an object.

39
Q

How is a method different from any other function?

A

It has a dot notation.

40
Q

How do you remove the last element from an array?

A

Using the pop() method

41
Q

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

A

Math.floor() method

42
Q

How do you generate a random number?

A

Math.random() method

43
Q

How do you delete an element from an array?

A

splice() method
splice(start, delete)

44
Q

How do you append an element to an array?

A

push() method

45
Q

How do you break a string up into an array?

A

split() method

46
Q

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

A

They do not, use console.log method on original string to verify

47
Q

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

A

No

48
Q

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

A

MDN

49
Q

Give 6 examples of comparison operators.

A

< > <= >= != == === !==

50
Q

What data type do comparison expressions evaluate to?

A

Boolean

51
Q

What is the purpose of an if statement?

A

Evaluate a condition to return a boolean and run instructions based on the boolean.
It allows us to make decisions in our code.

52
Q

Is else statement required in order to use an if statement?

A

No

53
Q

Describe the syntax (structure) of an if statement.

A

if {
is true {
do this
}
}

54
Q

What are the three logical operators?

A

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

55
Q

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

A

“use && ||”

56
Q

What is the purpose of a loop?

A

Loops allow an easy way to do something over and over.

57
Q

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

A

Condition’s ultimate goal is to check if the loop should move forward.
Ultimate goal is to stop the loop.

58
Q

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

A

A single repetition of the code block.

59
Q

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

A

Evaluated before each loop iteration. (iteration of the code block)

60
Q

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

A

Declared before the loop begins. Only runs one time.

61
Q

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

A

Evaluated before each loop iteration.

62
Q

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

A

After each iteration and before the condition

63
Q

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

A

break

64
Q

What does the ++ increment operator do?

A

adds +1 to the value permanently.

65
Q

How do you iterate through the keys of an object?

A

Use for for in loop.