JavaScript Flashcards
What is the purpose of variables?
To store data
How do you declare a variable?
Using the ‘var’ keyword
How do you initialize (assign a value to) a variable?
Using the “=” sign
What characters are allowed in variable names?
Must begin with a letter, ($), or (_)
Can’t start with numbers or use (-) or (.)
What does it mean to say that variable names are “case sensitive”?
value and Value are different variable names
What is the purpose of a string?
To store a string of characters
What is the purpose of a number?
To store a numeric value like amount
What is the purpose of a boolean?
To determine if something should be done; should code run
What does the = operator mean in JavaScript?
To assign, store a value to a variable
How do you update the value of a variable?
You re-assign a variable; don’t need to use the var keyword
What is the difference between null and undefined?
Undefined when variable is not assigned a value, null is purposeful emptiness;
Null has to be assigned
Why is it a good habit to include “labels” when you log values to the browser console?
Clarity for what is being logged
What are objects used for?
Group together a set of variables and functions to create a model of something.
What are object properties?
a variable that is part of an object
Describe object literal notation.
var object = { key: 'value', key: 40 }
How do you remove a property from an object?
Using the delete keyword;
delete object.propertyName
What are the two ways to get or update the value of a property?
Dot notation: object.popertyName;
Bracket notation: object[‘propertyName’];
Give five examples of JavaScript primitives.
strings, numbers, booleans, undefined, null
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
Combine 2 strings into a new string
What purpose(s) does the + plus operator serve in JavaScript?
Add numbers or concatenate strings
What data type is returned by comparing two values (greater than, less than, ===, etc.)
Booleans
What does the += “plus-equals” operator do?
Combines the variable and the value and assigns the new value to the variable
What are arrays used for?
To store a list of values