JavaScript Flashcards
(330 cards)
What is the purpose of variables?
to represent/store numbers and other kinds of data
How do you declare a variable?
first you declare a keyword (const, let, var) then you give the variable a name
How do you initialize (assign a value to) a variable?
you assign a variable a value by declaring it, then using an “=” (assignment operator) followed by the value you want to store
What characters are allowed in variable names?
letters
numbers
$
_ (underscore)
What does it mean to say that variable names are “case sensitive”?
if two words are spelled the same, but the cases are different, they will represent different variables
ex var Hello and var hello would be different variables
What is the purpose of a string?
to represent text content (letters and other characters). Must be inside quotations
What is the purpose of a number?
to represent quantities and other calculations involving numeric data
represent numeric data
What is the purpose of a boolean?
to represent “true” or “false” (ie on and off).
What does the = operator mean in JavaScript?
it is the assignment operator
How do you update the value of a variable?
declaring the variable name and using the assignment operator to assign it a new value
ex hello = “hello” reassigns the variable hello to “hello”
What is the difference between null and undefined?
null is an intentional assignment, you must assign a variable to “null” to display no value
undefined is when a variable is assigned no value, i.e. no assignment operator was used.
Why is it a good habit to include “labels” when you log values to the browser console?
to keep track of what variable is being logged and when.
Give five examples of JavaScript primitives.
string number boolean undefined null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining strings together to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
serves as addition and/or concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the variable (called on the left of the operator) to the value on the right of the operator and then assigns the called variable to the result of that expression.
What are objects used for?
serves as a grouping mechanism for other data types
What are object properties?
variables inside of an object
Describe object literal notation.
assigning an object to a variable name
declaring an object with curly braces
ex
var object = { property: value };
How do you remove a property from an object?
delete operator followed by the object name and property name you want to delete (can use dot or bracket notation).
What are the two ways to get or update the value of a property?
use dot or bracket notation to find the object and property you want and then assign it to a new value.
What are arrays used for?
storing a list of values that are related to each other in an ordered fashion