Week 2 Flashcards

1
Q

What is the purpose of variables?

A

The purpose of a variable is to store data.

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

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

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

We can use letters, $ dollar sign, _ underscore, and numbers but the word 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 a variable names are “case sensitive”?

A

It means that if the letter is capitalized or uncapitalized it makes a difference in calling a variable since it is two different variables. Score is not the same as score.

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

Consists of letters and other characters. They are used to add new content into a page and the can contain HTML markup.

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

Consists of numbers. Use for calculators, determining the size of the screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.

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

Boolean is either true or false. Considered like a light switch. It is helpful when determining which part of a script should run.

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

Initialize a variable

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

Using 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: It is the intentional absence of the value. It is one of the primitive values of JavaScript. Undefined: It means the value does not exist since there are no arguments.

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

It can be confusing without since we do not know what the console.log is printing if there is a lot. It would be easier to identify what is being consoled.

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

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

When connecting two 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

Used for addition. Adds one value to another.

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

The addition assignment (+=) operator adds the value of the right operand to a variable and assigns the result to the variable.

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

What are objects used for?

A

Objects group together a set of variables and functions to create a model of a something you would recognize from the real world.

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

What are object properties?

A

Variables become properties.

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

Describe object literal notation.

A

The object is the curly braces and their contents. The object is stored in a variable and would be referred to the name of the object when being called. Then inside the curly braces, you have properties. The properties are separated from the value using colon and you also separate each property or method using commas. Last, add a semicolon to the closing curly brace.

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

Using delete operator.
Ex: delete object.property

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

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

A

Using dot or 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

Consider using arrays whenever you are working with a list or a set of values that are related to each other.

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

Describe array literal notation.

A

Declare the array as a variable and then use square brackets and have your list inside of the square bracket and using commas to separate each content of the list.

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

Arrays are a special type of object. They hold a related set of key/value pairs, but the key for each values is its index number.

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

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

What is the length property of an array?

A

To tell us the total count of the array.

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

How do you calculate the last index of an array?

A

We can subtract 1 from the length property.

30
Q

What is a function in JavaScript?

A

A set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.

31
Q

Describe the parts of a function definition.

A

Function keyword to begin the creation of a new function. Followed by an optional name. Followed by a parameters surrounded by parentheses. Followed by the start of the function’s code block by an opening curly brace. Followed by an optional return statement. Followed by the closing curly brace to close the function’s code block.

32
Q

Describe the parts of a function call.

A

Call the function’s name and then it’s argument inside the parentheses.

33
Q

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

A

Function definition is creating the function with no arguments. Function call is when we put the arguments inside of the function to return what the function definition created.

34
Q

What is the difference between a parameter and an argument?

A

Parameter is used when defining a function while arguments are used when calling the function. Parameter is a placeholder; it is a variable whose value is not known until we call the function and pass an argument. When the function’s code block runs, the parameter will be holding the value of the argument.

35
Q

Why are function parameters useful?

A

Parameters allow a function to perform tasks without knowing the specific input values ahead of time.

36
Q

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

A

1) Causes the function to produce a value we can use in our program.c

2) Prevents any more code in the function’s code block from being run.

37
Q

Why do we log things to the console?

A

To check the console output to be sure your code is running correctly. It is a way to check back on your work.

38
Q

What is a method?

A

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

39
Q

How is a method different from any other function?

A

It is a property of an object.

40
Q

How do you remove the last element from an array?

A

pop() method

41
Q

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

A

floor() method of the math object

42
Q

How do you generate a random number?

A

random() method of the math object

43
Q

How do you delete an element from an array?

A

splice() method

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

Most string methods in JavaScript do not change the original string, but instead, return a new string with the desired modification. To check if a method changes the original string, you can check the documentation or look for the words “in-place” or “modifies the original string” in the description of the method.

However, if you’re not sure, you can always create a copy of the original string before calling the method and compare the two to see if the original string has been changed.

47
Q

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

A

50

48
Q

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

A

The return value of a JavaScript function or method can be useful in many situations, but not every situation requires its use. In some cases, the function may just perform an action, such as displaying a message on the screen, and in these cases, the return value may not be necessary.

49
Q

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

A

40-50

50
Q

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

A

MDN

51
Q

Give 6 examples of comparison operators.

A

=== strictly equal to, != is not equal to, > greater than, < less than, >= greater than equal to, <= less than equal too

52
Q

What data type do comparison expressions evaluate to?

A

Boolean

53
Q

What is the purpose of an if statement?

A

The if statement evaluates (or checks) a condition. If the condition evaluates to true, any statements in the subsequent code block are executed.

54
Q

Is else required in order to use an if statement?

A

No

55
Q

Describe the syntax (structure) of an if statement.

A

keyword if and then a condition within the parentheses then the opening curly brace followed by content within the code block and then the closing curly brace.

56
Q

What are the three logical operators?

A

&& and, || or, ! logical not

57
Q

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

A

Using the logical operator

58
Q

What is the purpose of a loop?

A

Loops check a condition. If it returns TRUE, a code block will run. Then the condition will be checked again and if it still remains TRUE, the code block will run again. It repeats until the condition returns FALSE.

59
Q

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

A

The loop should continue to run until the counter reaches a specified number.

60
Q

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

A

Each single pass through the sequence to complete all the steps in the given order is known as an iteration.

61
Q

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

A

At the beginning of each iteration

62
Q

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

A

At the beginning of each loop.

63
Q

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

A

Evaluated before each iteration.

64
Q

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

A

After the iteration.

65
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

66
Q

What does the ++ increment operator do?

A

Increases counter by 1

67
Q

How do you iterate through the keys of an object?

A

For in loops.

68
Q

What are the four components of “the Cascade”.

A

Source order, Specificity, Inheritance, Important

69
Q

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

A

The order of the style is based on the stylesheet from top to bottom.

70
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

inheritance

71
Q

List the three selector types in order of increasing specificity.

A

type, class, id

72
Q

Why is using !important considered bad practice?

A

it makes it difficult for other people if they make changes