JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Variables are used to store bits of data.

With a variable, we can assign a values to names, which will then be stored as a variable, and which we can return to later.

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

How do youdeclarea variable?

A

Using a variable keyword and a variable name…

var quantity;

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

Using an assignment operator and a variable value…

quantity = 3;

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

The name must begin with a letter, dollar sign, or an underscore. It must not start with a number.

The name can contain letters, numbers, dollar sign, or an underscore.
(Note that you must not use a dash or a period in a variable name. You also cannot use keywords or reserved words.)

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

It means that a variable with a capital letter and a variable with a lowercase letter would be two separate variables….

“score” and “Score” would be two different variable names. Javascript is sensitive to upper and lower casings.

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 are useful for storing characters/text data.
‘this is a string’

The strings data type consists of letters and other characters. This content is enclosed with double or single quotes. Strings can be used when working with any kind of text. They are frequently used to add new content into a page and they contain HTML markup.

Any character can be inside a string, including emojis

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 are useful for storing numeric value to do calculations, mathematical operations, or really anything having to do with numbers.

The numeric data type handles numbers. Numbers are not only used for things like calculators; they are also used for tasks such as 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

Booleans are useful for making decisions, like true or false, yes or no.

Boolean data types can have two values: true or false.

You can think of it a little like a light switch - it is either on or off. Booleans are 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

The = operator is an assignment operator and is used to assign values to variables.

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

You can state the variable name and assign it a new value. The old value will be replaced with the new value.

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

What is the difference betweennullandundefined?

A

Both mean ‘empty’, however, null is a developer’s way of saying ‘empty’, meanwhile undefined is javascript’s way of saying ‘empty’.

Null is a purposeful value. It is an intentionally assigned value of ‘nothing’ that must be put there on purpose. It’s typically used as a placeholder where value will be assigned later on.

Undefined appears organically from the javascript language and means that something has been declared but has not been defined (like declaring an empty variable).

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 is helpful to include labels when logging values that way you know exactly which value belongs to exactly which variable.

It also becomes extremely helpful in debugging and overall is a good habit so that the code stays clean and easy to understand.

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

Give five examples of JavaScript primitives.

A
Strings ('I am a string')
Numbers (24)
Booleans (true) (false)
Undefined (undefined)
Null (null)
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

Numbers!

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

What is string concatenation?

A

String concatenation is when you combine two strings together using the addition assignment to create a new string.

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

The addition operator (+) can be used in numerical calculations but can also be used to concatenate strings together.

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

A boolean value. (true/false)

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
(Addition assignment operator)
It adds the value of the righthand operand with the value of the lefthand variable, and reassigns the result of the expression to the variable.
	x += y 
	...is equal to...
	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

Objects are use to group together related variables.

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

What are object properties?

A

Object properties are variables within an object.

Object properties consist of keys and names which are stored as variables within an object. Technically, properties are variables, but they are properties when they live inside of an object.

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

Describe object literal notation.

A

Objects in literal notion consist of curly brackets in which there are properties. The properties consist of keys and values. Keys are separated from the values with a colon, and each property is separated with a comma. (The last property does not need a comma afterwards.)

Var object = {

car: ‘audi’,
color: ‘vibrant blue’,
convertible: true,
price: 70000
};
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 the delete operand in either dot or bracket notation…
delete object.color;
deleted object[‘color’];

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

Using dot notation or bracket notation.

dot notation:

object. color;
object. color = ‘red’;

bracket notation:
object[‘color’];
object[‘color’] = red;

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

What are arrays used for?

A

Arrays are a way to store data in a numbered list. Each array item is assigned to an index number.

Arrays are useful for lists or groups of similar data not needing their own label.

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

Describe array literal notation.

A

Array literal notation consists of values stored within square brackets, and separated by commas. Arrays can store multiple types of data and each value is assigned to an index number.

var array = [
     'item one',
     'item two',
     'item 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

Arrays are a special kind of object, where instead of values being assigned to key names, the values are instead assigned to an index in numerical order.

Arrays bring different benefits as opposed to plain objects because of this. Like how you can access values by their index number, or check to see the total number of values stored within the array. It is also useful when storing data in which you don’t know how much room you’ll need, since you can continue to add or delete values from an array without first declaring a spot for them.

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.

A computer begins counting from 0.
Therefore, the first item in an array would be item # 0. The tenth item in an array would be item # 9.

28
Q

What is thelengthproperty of an array?

A

The length property of an array is used to find out how many items exist in an array.

using array.length, you can find the # of values stored.

29
Q

How do you calculate the last index of an array?

A

The amount of values stored minus 1.

This is because the computer begins counting from zero. In an array with 10 items, the last item would have an index number of 9.

30
Q

What is a function in JavaScript?

A

Functions are blocks of code in JavaScript which can be called upon again and again to deliver different results. (aka, a re-usable block of code)

Functions in javascript are a set of statements that perform a task or calculate a value for a specific purpose. Functions 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 functiondefinition.

A

The parts of function definition include

a function keyword to begin the creation of a new function, 
an optional name, 
a comma-separated list of zero or more parameters surrounded by parenthesis, 
the start of a function’s code block, as indicated by an { opening curly brace, 
an optional return statement, 
the end of the function’s code block, as indicated by a } closing curly brace.
function sayHello(name) {
     return 'Hello ' + name + '!';
}
32
Q

Describe the parts of a functioncall.

A

The parts of a function call include

The function’s name,
A comma separated list of zero or more arguments surrounded by parenthesis.

(function calls do not require arguments if the function definition did not include parameters)

sayHello(‘Aless’);

33
Q

When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?

A

A function definition includes the function keyword, potential parameters, and the code block.

A function call includes the function name & potential arguments.

34
Q

What is the difference between aparameterand anargument?

A

When we define a function, we declare parameters.
When we call a function, we pass it arguments.

Parameters are simply placeholders for arguments.

Parameters = passive
Arguments = active
35
Q

Why are functionparametersuseful?

A

Parameters are useful because they allow us to create placeholders for arguments.

They are variables whose values are not known until we assign it the value of an argument. Therefore, we can assign one function different values at different times, creating a dynamic function that is capable of delivering different results.

36
Q

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

A
  1. Causes the function to produce a value we can use in our program.
    1. Prevents any more code in the function’s code block from being run.
37
Q

Why do we log things to the console?

A

For verification and working through issues / as a debugging tool.
It’s dangerous to make assumptions about the code, so logging is imperative to double-check our work and to make sure it is correct + doing what we want it to do.

It also is very helpful in learning, as logging throughout code can help to evaluate the process and see things taking place and when.

38
Q

What is a method?

A

Methods are functions that are properties of an object

39
Q

How is a method different from any other function?

A

Methods are different from functions because they are not called on their own. They have to be called as the property of an object.

Array.push();

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

Using the floor() method of the Math object (it will round a number down to the nearest integer).

TheMath.floor()function returns the largest integer less than or equal to a given number.
	ciel() will round up
	And round() will overall round
42
Q

How do you generate a random number?

A

The random() method of the Math object.

43
Q

How do you delete an element from an array?

A

Using the splice() method.

Array.splice(1, 1)
Parameter 1 specifies at which index to begin deletion.
Parameter 2 specifies how many to delete.

or the delete operator.
delete array[2]

Also, the pop() method will remove the last element from an array, and the shift() method will remove the first element from an array

    array. pop()
    array. shift()
44
Q

How do you append an element to an array?

A
The push() method will add an element at the end of the array.
array.push()

(the unshift() method will add an element at the start of an array)
array.unshift()

45
Q

How do you break a string up into an array?

A

Using the split() method.

46
Q

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

A

No, string methods do not change the original state of a string. Check by console logging the original string.

You can also more thoroughly check what happened by returning the result of a string method to a new variable, then console.logging both variables to check the differences.

47
Q

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

A

A lot. Roughly 33.

48
Q

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

A

Not every situation, sometime yes and sometimes no.

Return values can be relevant but aren’t always important. Though, in some place or other, it is relevant in some way (and as part of a bigger picture). So that is why return values exist.

49
Q

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

A

A lot. Roughly 31.

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
===   strict equal to
!==   strict not equal to
>   greater than
>=   greater than or equal to
<   less than
<=   less than or equal to
52
Q

What data type do comparison expressions evaluate to?

A

Comparison expressions will evaluate to a boolean value.

True if true / false if false

53
Q

What is the purpose of anifstatement?

A

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

aka. They allow us to make decisions and to program code to run depending on the answers.

54
Q

Iselserequired in order to use anifstatement?

A

No, else is not required.

Else is there in case your initial condition was not true and you want other code to run as an alternative.

55
Q

Describe the syntax (structure) of anifstatement.

A

An if statement includes…

the if keyword
a condition
and a code block within curly braces
56
Q

What are the three logical operators?

A

&&. logical and
|| logical or
! logical not

57
Q

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

A

Place a logical and / logical or operator between the expressions to compare the two expressions with each other, thus creating a third expression.

(2 > 3 && 5 > 4)

You can put each expression within parenthesis though it is not necessary.

( (2 > 3) || (5 > 4) )

58
Q

What is the purpose of a loop?

A

Loops offer a quick and easy way to do something repeatedly.

They allow us to repeat a block of code again and again depending on a condition and as long as the condition is true.

59
Q

What is the purpose of aconditionexpression in a loop?

A

The condition allows the loop to run if it is true, and also brings the loop to a stop once the condition is no longer true.

It plays the role of the green light and the red light, giving the code permission to go and to stop.

60
Q

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

A

“Iteration” refers to each run-through/pass-through of the loop.

Iteration is each time the code block runs.

61
Q

Whendoes theconditionexpression of awhileloop get evaluated?

A

The condition expression in a while loop is the first thing to be evaluated and continues to be evaluated at the beginning of each iteration. Once the condition is false, the loop is terminated.

62
Q

Whendoes theinitializationexpression of aforloop get evaluated?

A

The initialization expression is the first to be evaluated. It initializes the loop and is only evaluated once before the loop begins. It does not get evaluated again and the results of the initialization expression are discarded.

63
Q

Whendoes theconditionexpression of aforloop get evaluated?

A

The condition expression in a for loop is evaluated at the beginning of each iteration. It the condition is true, the code block runs. Once the condition is false, the loop is terminated.

64
Q

Whendoes thefinalexpression of aforloop get evaluated?

A

The final expression is the last to be evaluated in a for loop. It is evaluated at the end of each iteration, after the condition and the code block. Typically, the final expression is used to update or increment the counter variable.

65
Q

Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?

A

The break keyword.

66
Q

What does the++increment operator do?

A

The increment operator (++) increments (adds one to) its operand and returns a value.
x = x + 1 is the same as x++

67
Q

How do you iterate through the keys of an object?

A

Using a for…in loop

for (const prop in object)
for (var key in object)

(Thefor…instatementiterates over allenumerable propertiesof an object that are keyed by strings.)