Javascript Flashcards
(183 cards)
What is the purpose of variables?
to store information to be referenced/accessed later
How do you declare a variable?
use the keyword “var”
- var newVariable
- (also use const/let)
How do you initialize (assign a value to) a variable?
put an equals sign after the variable you want to initialize, and then put the value after the equals sign
e.g. newVariable = ‘new value’
What characters are allowed in variable names?
- variable must begin with: letter, $, or _. after that, numbers can be used as well
- cannot use keywords
What does it mean to say that variable names are “case sensitive”?
capital and lower casing matter
What is the purpose of a string?
stores a sequence of characters (text)
What is the purpose of a number?
gives us a numeric value as a constant to work with
What is the purpose of a boolean?
indicates two possible values (true/false)
What does the = operator mean in JavaScript?
assigns a value to the variable that’s on the left of the operator
How do you update the value of a variable?
varName = ‘new updated value’
What is the difference between null and undefined?
- null is an object with the assigned value of “no value”
- undefined is a type, where the variable is undeclared or undefined (not been given a value)
- in your code, you should not use “undefined”. undefined is generally used for debugging
Why is it a good habit to include “labels” when you log values to the browser console?
so that you know the context for the printed value
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?
combination of 2+ values
What purpose(s) does the + plus operator serve in JavaScript?
adding number values or concatenation
What does the += “plus-equals” operator do?
adds the right-hand value onto the left-hand value and assigns it to the left-hand value
—> (x += 5) is the same as (x = x+5)
What are objects used for?
used to hold a collection of properties and methods
What are object properties?
a name-value pair that tells us more about the object
Describe object literal notation
objectName = { name: value, name2: value2, name3: value3 }
How do you remove a property from an object?
delete objectName.propertyName
What are the two ways to get or update the value of a property?
dot notation, bracket notation
- dot notation is very literal. property identifiers cannot be a variable, or start w a number, or have spaces, etc
- bracket notation has fewer limitations. property identifiers can be variables
What are arrays used for?
arrays store a collection of elements of the same data type
Describe array literal notation.
var newArray = []