JavaScript Flashcards
what is the purpose of variables?
to store data
how do you declare a variable?
with the keyword var
how do you initialize a variable?
with the assignment operator
what characters are allowed in variable names?
letters, numbers, _, $. can NOT start with number
what does it mean to say that variable names are “case sensitive”
name must be exact including if a letter is uppercase or lowercase
what is the purpose of a string?
storing and manipulating text.
what is the purpose of a number?
to perform calculations
what is the purpose of a boolean?
to determine what is run in JS
what does the = operator mean in JavaScript?
assignment operator
how do you update the value of a variable?
reassign using assignment operator
what is the difference between null and undefined?
undefined is not defined.
null was purposely set to null
why is it a good habit to include labels when you log values to the console?
to keep track of what you’re logging.
give 5 examples of JavaScript primitives
string, number, boolean, undefined, null
what data type is returned by an arithmetic operation
a number
what is a string concatenation
joining two or more strings.
what purpose(s) does the + plus operator serve in JavaScript?
addition and concatenation
what data type is returned by comparing two values?
a boolean
what does the += plus equals operator do?
adds then assigns new value
what are objects used for?
to group variables and functions
what are object properties?
variables within an object
describe object literal notation
{ key:value, key:value}
how do you remove a property from an object?
keyword delete & dot notation or square bracket notation
what are the two ways to get or update the value of a property?
dot notation and square bracket notation
what are arrays used for?
storing a list of values
describe array literal notation
[value, value]
how are arrays different from ‘plain’ objects?
the key for each value is an index
what number represents the first index of an array?
0
what is the length property of an array?
.length
how do you calculate the last index or an array.
subtract 1 from the length
what is a function in javascript?
a block of code designed to perform a particular task.
describe the parts of a function definition
function keyword, function name, parameters, code block.
describe the parts of a function call
function name, arguments.
when comparing side by side what are the differences between a function call and a function definition?
call has arguments, definition has parameters and code block.
what is the difference between a parameter and an argument
parameters are placeholders within definition, arguments are to pass into a function call.
why are function parameters so useful?
to use a function multiple times with different arguments.
what 2 effects does a return statement have on the behavior of a function?
causes a value to be produced from function, ends the function
why do we log things to the console?
to check if the code is working properly
what is a method?
a function stored within an object
how is a method different from a function
a method is attached to an object
how do you remove the last element from an 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?
.splice(start, amount)
how do you append an element to an array?
.unshift, .push, .splice
how do you break a string up into an array?
.split(onCharacter)
do string methods change the original string? how would you check if you weren’t sure?
No, strings are immutable. you could check in the console.
roughly how many string methods are there according to the MDN Web docs?
roughly 40
is the return value of a function or method always useful?
no
roughly how many array methods are there according to the MDN Web docs?
roughly 40
what 3 letter acronym should you always include in your google search about javascript method and 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 determine what code runs
describe the syntax of an if statement
if keyword (condition statement) { code block }
what are the 3 logical operators?
&&, ||, !
how do you compare 2 different expressions in the same condition?
&& or ||
what is the purpose of a loop?
to repeat behavior
what is the purpose of a condition in a loop?
to check if the loop keeps going or ends.
what does iteration mean in the context of loops?
each time the code in the loop runs
when does the condition expression of a while loop get evaluated?
before each loop iteration
when does the initialization expression of a for loop get evaluated?
before everything. only once
when does the condition of a for loop get evaluated?
before each loop iteration
when does the final expression of a for loop get evaluated?
after the code block runs during each loop iteration.
besides a return statement, which keyword exits a loop before its condition expression evaluates to false?
break
what does the ++ increment operator do?
increments by 1
how do you iterate through the keys of an object?
for…in loop
what is a ‘model’
a copy
which ‘document’ is being referred to in the phrase Document Object Model
HTML