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
What are arrays used for?
stores a (ordered) list of values (numbers, booleans, strings, arrays, objects)
26
Describe array literal notation.
var array = ['one', 2, false]
27
How are arrays different from "plain" objects?
Arrays, by nature, are ordered lists (and numerically indexed)
28
What number represents the first index of an array?
0 (zero)
29
What is the length property of an array?
Returns a numeric value of how many elements are in the array. array.length = (some number)
30
How do you calculate the last index of an array?
array.length - 1
31
What is a function in JavaScript?
functions are sets of code that can be called/executed again after they have been created with a specific name and (sometimes) arguments.
32
Describe the parts of a function definition.
function (keyword) functionName(parameter1, parameter2) { code block }
33
Describe the parts of a function call.
functionName(argument1, argument2)
34
When comparing them side-by-side, what are the differences between a function call and a function definition?
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
What is the difference between a parameter and an argument?
parameter used in the definition, arguments used in call
36
Why are function parameters useful?
can provide more interact-able results when users/ programs put parameters in the function give code more flexibility
37
What two effects does a return statement have on the behavior of a function?
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
Why do we log things to the console?
debug and make sure we know what data we are working with
39
What is a method?
A method is a function which is a property of an object.
40
How is a method different from any other function?
method is always directly associated with an object, a function operates on its own.
41
How do you remove the last element from an array?
object.pop()
42
How do you round a number down to the nearest integer?
Math.floor()
43
How do you generate a random number?
Math.random()
44
How do you delete an element from an array?
object.splice(location, delete location) object.shift() beginning object.pop() end
45
How do you append an element to an array?
object.push() end object.unshift() beginning
46
How do you break a string up into an array?
object.split() puts split contents into array.
47
Do string methods change the original string? How would you check if you weren't sure?
no they don't change-- you can console.log() to check primitives are immutable
48
Roughly how many string methods are there according to the MDN Web docs?
around 50 or so
49
Is the return value of a function or method useful in every situation?
no, not always (object.pop() we might not need the popped item)
50
Roughly how many array methods are there according to the MDN Web docs?
around 40 or so
51
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
52
Give 6 examples of comparison operators.
<, <=, >, >=, ===
53
What data type do comparison expressions evaluate to?
boolean (true/ false)
54
What is the purpose of an if statement?
runs specific code if the condition is true
55
Is else required in order to use an if statement?
no, not technically required, just code in if statement won't run if conditions are not met
56
Describe the syntax (structure) of an if statement.
if ( x ??? y) { code block }
57
What are the three logical operators?
&&, ||, !
58
How do you compare two different expressions in the same condition?
use a logical operator depending on situation.
59
What is the purpose of a loop?
execute a code block for a certain (or infinite) amount of times good for arrays, objects.
60
What is the purpose of a condition expression in a loop?
will run code block as long as condition returns true, quits the loop when condition is false
61
What does "iteration" mean in the context of loops?
one complete execution of the code in the loop
62
When does the condition expression of a while loop get evaluated?
Before each pass of the loop. If returning false, loops stops.
63
When does the initialization expression of a for loop get evaluated?
Once, before the loops begins
64
When does the condition expression of a for loop get evaluated?
Before each pass of the loop. If returning false, loops stops.
65
When does the final expression of a for loop get evaluated?
after the code block is executed at the end of each pass
66
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
67
What does the ++ increment operator do?
adds by 1
68
How do you iterate through the keys of an object?
for (x in object) { codeblock }
69
What are the four components of "the Cascade".
source order, inheritance, specificity, !important
70
What does the term "source order" mean with respect to CSS?
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
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?
certain child elements automatically inherit certain properties from the parent
72
List the three selector types in order of increasing specificity.
type (h1, p, div, ::pseudo-element) class (.myClass, [type=radio]) id (#myID)
73
Why is using !important considered bad practice?
ignores specificity of elements and can cause difficulties in the future when wanting to target other selectors.