JavaScript Flashcards
What is the purpose of variables?
to store data (temporarily) that can be accessed later
have a value that persists
How do you declare a variable?
var variableName;
How do you initialize (assign a value) to a variable?
var variableName = (variable value);
What characters are allowed in variable names?
letters, numbers, dollar signs, underscore
no dash or period
cannot start with a number
What does it mean to say that variable names are “case sensitive”?
score != Score
What is the purpose of a string?
store data with text content
save a series of characters
What is the purpose of a number?
count, math, measurement
What is the purpose of a boolean?
to make decisions
determine which part of a script should run
What does the = operator mean in JavaScript?
assignment operator
assigns a value to a variable
updates value given to a variable
How do you update (reassign) the value of a variable?
using equal sign (assignment operator) to assign it a new value
var is only necessary the first time
What is the difference between null and undefined?
null means no value
undefined means variable has not been declared/given a value
null MUST be assigned
Why is it a good habit to include “labels” when you log values to the browser console?
to know which value or variable is being logged
helpful for catching bugs
Give 5 examples of JavaScript primitives
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
a number (always)
What is string concatenation?
combination of two or more string values (or number)
What purpose(s) does the + operator serve in JavaScript?
adds on value to another or concatenation
What data type is returned by comparing two values?
a boolean true or false
What does the += operator do?
adds the value of the value on right to the current variable and assigns the result to that variable
What are objects used for?
storing a set of variables and functions
bringing data together
create a collection of stuff that make sense
What are object properties?
individual pieces of data stored in an object
Describe object literal notation
The object which contains a set of properties and values inside curly braces being assigned to a variable
How do you remove a property from an object?
Use the delete operator followed by the object and property name
What are the two ways to get or update the value of a property?
dot or bracket notation
What are arrays used for?
storing a list or set of values that are related to each other
Describe array literal notation.
var nameOfArray = straight brackets filled with items
How are arrays different from “plain” objects?
the keys for the values of the array are indexed
to add something to array: push method
What number represents the first index of an array?
0
What is the length property of an array?
holds the number of items in an array
How do you calculate the last index of an array?
nameOfArray.length - 1;
What is a function in JavaScript?
a special kind of object that can be called and reused to perform a task
Describe the parts of a function defintion
function keyword and name of the function, called with 0 or more parameters, with the code block enclosed in curly braces
Describe the parts of a function call
function name with parentheses called with 0 or more params
When comparing them side-by-side, what are the diffs between a function call and a function definition?
calling a function requires the name of the function with arguments function definition is the function itself that takes parameters
What is the diff between a parameter and an argument?
argument: passed into function when it’s called
parameter: tied to the function definition
Why are function parameters useful?
to pass additional info into the function and have dynamic data
gives us a tool that can be more generalized
What two effects does a return statement have on the behavior of a function?
prevents any more code in function’s code block to be run
produces values / exits the function