JavaScript Flashcards
What is the purpose of variables?
Store results, quantities, conditionals
How do you declare a variable?
Keyword var and variable name
How do you initialize (assign a value to) a variable?
Use ‘=’
What characters are allowed in variable names?
$, letters, numbers
What does it mean to say that variable names are “case sensitive”?
lowercase names are not the same as capitalizes names
What is the purpose of a string?
To manipulate text
What is the purpose of a number?
math and quantities
What is the purpose of a boolean?
conditionals
What does the = operator mean in JavaScript?
Assigning value
How do you update the value of a variable?
Assign a new value
What is the difference between null and undefined?
Different data types. Null always needs to be assigned.
Why is it a good habit to include “labels” when you log values to the browser console?
So you know what the logged values are for.
Give five examples of JavaScript primitives.
boolean, number, string, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Appending strings to make a new string.
What purpose(s) does the + plus operator serve in JavaScript?
Adding numbers, concatenating strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Adds/appends and assigns the new value
What are objects used for?
Store related values
What are object properties?
Keys to access object’s values
Describe object literal notation.
Curly braces + key, value pairs
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
Dot notation or brackets
Why do we log things to the console?
To check for expected output of functions and objects
What is a method?
Function of an object
How is a method different from any other function?
Function is stand-alone. Methods belong to objects and are called by first referencing the object.
How do you remove the last element from an array?
pop
How do you round a number down to the nearest integer?
floor()
How do you generate a random number?
random()
How do you delete an element from an array?
pop, shift, splice
How do you append an element to an array?
push
How do you break a string up into an array?
split
Do string methods change the original string? How would you check if you weren’t sure?
No, strings are immutable. Check MDN.
Roughly how many string methods are there according to the MDN Web docs?
Several dozen
Is the return value of a function or method useful in every situation?
No
Roughly how many array methods are there according to the MDN Web docs?
Several dozen
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
!==, ===, >=, >,
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
To check a condition
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
If { /* code */ }
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
Use &
What is the purpose of a loop?
To repeat code as many times as needed
What is the purpose of a condition expression in a loop?
Determines whether to continue the loop
What does “iteration” mean in the context of loops?
Each cycle of the loop
When does the condition expression of a while loop get evaluated?
Before each iteration
When does the initialization expression of a for loop get evaluated?
Beginning of the loop
When does the condition expression of a for loop get evaluated?
Before each iteration
When does the final expression of a for loop get evaluated?
After the code block is run.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
Increments the variable it’s called on by one
How do you iterate through the keys of an object?
for key in object