JavaScript Flashcards
(172 cards)
what is the purpose of a variable?
to store information to be referenced to
How do you declare a variable?
variable keyword and variable name
How do you initialize (assign a value to) a variable?
with an = sign (assignment operator) and a variable value after it
var nameOfVar = value (string, number, boolean data type)
What characters are allowed in variable names?
letters, numbers, dollar sign, or underscore
but a number cannot be the first character
What does it mean to say that variable names are “case sensitive”?
when you call the variable name, you have to call it by its exact value or the computer won’t recognize it
What is the purpose of a string?
to store a collection of characters (could be a letter, number, or a backslash)
What is the purpose of a number?
to store numbers
What is the purpose of a boolean?
to determine which code should run?
to store true/false value
What does the = operator mean in JavaScript?
variable assignment
provide variable value to a variable
How do you update the value of a variable?
call the variable name, assignment operator, and the new variable value
What is the difference between null and undefined?
null is an assigned value– it means there is nothing in the variable
undefined means a variable has been declared but not defined with values yet
as a developer, you never want to assign a variable as undefined
Why is it a good habit to include “labels” when you log values to the browser console?
so you can tell which variables are being logged and in what order– this is especially helpful when you need to debug
Give five examples of JavaScript primitives.
Number, String, Boolean, Null, Undefined
What data type is returned by an arithmetic operation?
number
What purpose(s) does the + plus operator serve in JavaScript?
to concatenate strings or add numbers
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds/concatnates value from the right to the left variable
the current value of that variable, bring in some value, add that on to the current value, and the result of that is the new value
What is string concatenation?
the process of joining multiple strings together
What are objects used for?
used to group together a set of variables and functions to create a model
What are object properties?
a variable– properties tell us about the object
Describe object literal notation.
its an array of key-value pairs with a colon separating the keys and values and a comma after every key-value pair (except for the last)
How do you remove a property from an object?
you use the delete keyword followed by the object name and the property name
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What are object methods?
a function– methods represent tasks that are associated with the object