Week 2 Quiz Questions Flashcards

1
Q

What is the purpose of variables?

A

Variables are used to store temporary data (esp in scripts)

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

How do you declare a variable?

A

Variable syntax:
var nameOfVariable = “string”
with var

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

Variable syntax:
var nameOfVariable = “string”
with the equals sign (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

letters, dollar signs, underscores, numbers.
cannot start with a number

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

Upper and Lower case changes the variable you are using:
camelCase and camelcase would be different variables.

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

stores 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

used in counting/ calculating sums

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

has a value of true or false

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 operator used when assigning variables to a value

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

declare the variable again (without var) and put the updated value on the other side of the assignment operator

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- variable that has no value
undefined- variable that has just been declared and doesnt have a value YET

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

Shows user which variable/ object/ data type they are logging to the console. for neatness and clarity

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

*

 and <style> similarities*</style>
A

CSS should be written in css files and console.log/js functions should be written in the js file
generally shouldnt (need to) write code within <style> and

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

What is string concatenation?

A

combining two or more strings (or other primitive data types) into a new string that has both values combined

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

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

A

in both arithmetic with numbers and string concatenation.

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

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

A

adds the value of the right operand to a variable and assigns the value to that same variable

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

What are objects used for?

A

objects store sets of data (properties: keys and values, and methods: keys and functions)

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

What are object properties?

A

a variable that is stored in an object (key: value pairs)

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

Describe object literal notation.

A

var object = {
key: value
}

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

How do you remove a property from an object?

A

with ‘delete’:
delete object.property

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

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

A

can be used with either dot notation (object.dot) or bracket notation (object[“bracket”])

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

What are arrays used for?

A

stores a (ordered) list of values (numbers, booleans, strings, arrays, objects)

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

Describe array literal notation.

A

var array = [‘one’, 2, false]

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

How are arrays different from “plain” objects?

A

Arrays, by nature, are ordered lists (and numerically indexed)

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

What number represents the first index of an array?

A

0 (zero)

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

What is the length property of an array?

A

Returns a numeric value of how many elements are in the array.
array.length = (some number)

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

How do you calculate the last index of an array?

A

array.length - 1

31
Q

What is a function in JavaScript?

A

functions are sets of code that can be called/executed again after they have been created with a specific name and (sometimes) arguments.

32
Q

Describe the parts of a function definition.

A

function (keyword) functionName(parameter1, parameter2) { code block }

33
Q

Describe the parts of a function call.

A

functionName(argument1, argument2)

34
Q

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

A

function definition has the keyword ‘function’ and parameters instead of function call arguments. function definitions also have a code block that the call doesnt have, but executes.

35
Q

What is the difference between a parameter and an argument?

A

parameter used in the definition, arguments used in call

36
Q

Why are function parameters useful?

A

can provide more interact-able results when users/ programs put parameters in the function

give code more flexibility

37
Q

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

A

produces a value that can be used in our program and also exits the function/ code block the first instance the code runs into a return.

38
Q

Why do we log things to the console?

A

debug and make sure we know what data we are working with

39
Q

What is a method?

A

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

40
Q

How is a method different from any other function?

A

method is always directly associated with an object, a function operates on its own.

41
Q

How do you remove the last element from an array?

A

object.pop()

42
Q

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

A

Math.floor()

43
Q

How do you generate a random number?

A

Math.random()

44
Q

How do you delete an element from an array?

A

object.splice(location, delete location)
object.shift() beginning
object.pop() end

45
Q

How do you append an element to an array?

A

object.push() end
object.unshift() beginning

46
Q

How do you break a string up into an array?

A

object.split() puts split contents into array.

47
Q

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

A

no they don’t change– you can console.log() to check
primitives are immutable

48
Q

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

A

around 50 or so

49
Q

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

A

no, not always (object.pop() we might not need the popped item)

50
Q

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

A

around 40 or so

51
Q

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

A

MDN

52
Q

Give 6 examples of comparison operators.

A

<, <=, >, >=, ===

53
Q

What data type do comparison expressions evaluate to?

A

boolean (true/ false)

54
Q

What is the purpose of an if statement?

A

runs specific code if the condition is true

55
Q

Is else required in order to use an if statement?

A

no, not technically required, just code in if statement won’t run if conditions are not met

56
Q

Describe the syntax (structure) of an if statement.

A

if ( x ??? y) {
code block
}

57
Q

What are the three logical operators?

A

&&, ||, !

58
Q

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

A

use a logical operator depending on situation.

59
Q

What is the purpose of a loop?

A

execute a code block for a certain (or infinite) amount of times
good for arrays, objects.

60
Q

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

A

will run code block as long as condition returns true, quits the loop when condition is false

61
Q

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

A

one complete execution of the code in the loop

62
Q

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

A

Before each pass of the loop. If returning false, loops stops.

63
Q

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

A

Once, before the loops begins

64
Q

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

A

Before each pass of the loop. If returning false, loops stops.

65
Q

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

A

after the code block is executed at the end of each pass

66
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

67
Q

What does the ++ increment operator do?

A

adds by 1

68
Q

How do you iterate through the keys of an object?

A

for (x in object) { codeblock }

69
Q

What are the four components of “the Cascade”.

A

source order, inheritance, specificity, !important

70
Q

What does the term “source order” mean with respect to CSS?

A

the order in which css ruleset is written in a .css file. the last ruleset is the one that is applied if the specificity of all elements are the same

71
Q

How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?

A

certain child elements automatically inherit certain properties from the parent

72
Q

List the three selector types in order of increasing specificity.

A

type (h1, p, div, ::pseudo-element)
class (.myClass, [type=radio])
id (#myID)

73
Q

Why is using !important considered bad practice?

A

ignores specificity of elements and can cause difficulties in the future when wanting to target other selectors.