JavaScript Flashcards
What is the purpose of variables?
a place to store data for the future
How do you declare a variable?
var “variable name” = value
How do you initialize (assign a value to) a variable?
with an equal sign
What characters are allowed in variable names?
letters, numbers(not first character), $, _
What does it mean to say that variable names are “case sensitive”?
letter casing creates unique variables
What is the purpose of a string?
basically text content
What is the purpose of a number?
to count and do math
What is the purpose of a boolean?
to show true/false, on/off
What does the = operator mean in JavaScript?
it means to assign value
it’s an assignment operator
How do you update the value of a variable?
“variable name” = new value
What is the difference between null and undefined?
null is null, undefined means no assigned value
Why is it a good habit to include “labels” when you log values to the browser console?
for ease of use later on
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number operator
What is string concatenation?
combining strings together
What purpose(s) does the + plus operator serve in JavaScript?
addition or concatination
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds left operand to right operand then assigns result to left operand
What are objects used for?
grouping data to represent an actual thing
What are object properties?
variables inside of an object
Describe object literal notation.
{ property: property name,
property name};
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 bracket notation
What are arrays used for?
making lists of data
Describe array literal notation.
var ‘name’ = [value, value, value]
How are arrays different from “plain” objects?
arrays store in an ordered list with solely a data-type, no property name required
What number represents the first index of an array?
[0]
What is the length property of an array?
How ever many items are currently inside of it -1
How do you calculate the last index of an array?
items in an array -1
What is a function in JavaScript?
a set of statements that perform a repeatable task
Describe the parts of a function definition.
keyword, name, (parameters), {function block}, return keyword
Describe the parts of a function call.
function name(list of arguments)
When comparing them side-by-side, what are the differences between a function call and a function definition?
parameters/arguments
code block in def, not in call
call will always have ( )
function keyword in def not call
What is the difference between a parameter and an argument?
parameters are placeholders in a definition
arguments become the value of that placeholder
Why are function parameters useful?
they can help describe what kind of data will be used later as the argument
What two effects does a return statement have on the behavior of a function?
a return replaces a function call
Why do we log things to the console?
to confirm the result of an action
What is a method?
a function which is the property of an object
How is a method different from any other function?
JS functions are not objects so a method is a reference to a function
How do you remove the last element from an array?
array.pop( )
How do you round a number down to the nearest integer?
Math.floor( )
How do you generate a random number?
Math.random
How do you delete an element from an array?
array.splice(start, delete)
How do you append an element to an array?
array.push( )
How do you break a string up into an array?
string.split( )
Do string methods change the original string? How would you check if you weren’t sure?
they don’t, check by just doing it and console.logging the original string
Is the return value of a function or method useful in every situation?
no
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?
Booleans
What is the purpose of an if statement?
make a decision
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condition) { what happens}
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
with a && or || operator
What is the purpose of a condition expression in a loop?
when to stop the loop
What is the purpose of a loop?
run a block multiple times
What does “iteration” mean in the context of loops?
single run of the code-block
When does the condition expression of a while loop get evaluated?
before each code block runs
When does the initialization expression of a for loop get evaluated?
before the loop begins, only once
When does the condition expression of a for loop get evaluated?
after the initialization, before each iteration
When does the final expression of a for loop get evaluated?
after each iteration
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 value of a var by one and substitutes that value to the var
How do you iterate through the keys of an object?
for in loop
Why do we log things to the console?
to make sure funcitons/methods call correctly and verifying input to outputs
What is a “model”?
a representation of something
Which “document” is being referred to in the phrase Document Object Model?
the html document thats been linked to the JS document
What is the word “object” referring to in the phrase Document Object Model?
a datatype used to represent and recreate the document it’s referencing to make changes on
What is a DOM Tree?
a representative chunk of a page built as JS objects