Javascript Flashcards
What is the purpose of variables?
variables are used to store data that can be accessed later
How do you declare a variable?
a keyword (like var) then the name of the variable
How do you initialize (assign a value to) a variable?
variable name = (assignment operator) value
What characters are allowed in variable names?
letters, numbers, $, _
What does it mean to say that variable names are “case sensitive”?
variables spelled with the same characters but have differences in capitalization are considered different
What is the purpose of a string?
stores data containing a series of characters
What is the purpose of a number?
used for calculations, determining the size, movement, or time associated with something
What is the purpose of a boolean?
defines whether something is true or false, for decisions
What does the = operator mean in JavaScript?
assignment operator
How do you update the value of a variable?
variableName = new value
What is the difference between null and undefined?
null is the intentional absence of value
Why is it a good habit to include “labels” when you log values to the browser console?
labels provide context to whatever you log in the console
Give five examples of JavaScript primitives.
strings, numbers, booleans, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining a string with another value to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
adds numbers and concatenates strings
What data type is returned by comparing two values ( > , < , ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value to the right of the operator to the value on the left and assigns the result to the variable on the left
What are objects used for?
group together a set of related variables and functions
What are object properties?
variables that are part of an object
Describe object literal notation.
objectName = { property : value, … } ;
How do you remove a property from an object?
delete keyword followed by the objectName.propertyName
What are the two ways to get or update the value of a property?
dot or bracket notation
What are arrays used for?
arrays store a list of values that are related to each other
Describe array literal notation.
arrayName = [ value, … } ;
How are arrays different from “plain” objects?
the keys are index numbers, so there’s a specific order to the values
What number represents the first index of an array?
[ 0 ]
What is the length property of an array?
the number of entries in an array
How do you calculate the last index of an array?
arrayName.length - 1
What is a function in JavaScript?
section of code that performs a task and can be reused
Describe the parts of a function definition.
function keyword, function name, ( ) with 0 or more parameters, { } code block, and and optional return statement
Describe the parts of a function call.
function name, ( ) containing the argument(s)
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition has a function keyword, parameters, { } containing a code block. function call only has the function name and arguments in ( )
What is the difference between a parameter and an argument?
parameters are for definition, arguments are for calls
Why are function parameters useful?
they allow different arguments to be passed through a function
What two effects does a return statement have on the behavior of a function?
return statements stop the code block from running and make the function produce a value
Why do we log things to the console?
to make sure our code is working properly and producing the expected results
What is a method?
a function that is a property of an object
How is a method different from any other function?
methods are a part of an object, they must be called with the 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( ) * (range + 1) + start
How do you delete an element from an array?
.splice(index, # of items deleted)
How do you append an element to an array?
.push( )