JS 1 Flashcards
What is the purpose of variables?
variables are assigned data, and allow for referring to them later to access that data
How do you declare a variable?
“var” or “let” keyword followed by the name
How do you initialize (assign a value to) a variable?
variable name, equal sign, followed by value assigned
What characters are allowed in variable names?
numbers, letters, _, $
What does it mean to say that variable names are “case sensitive”?
case (lowercase/uppercase) needs to be exact, since they are differentiated in javascript
What is the purpose of a string?
a string is made up of characters in a row and is used to store text
What is the purpose of a number?
a number is for numeric value and used in mathematical operations
What is the purpose of a boolean?
booleans allow for the ability to make decisions based on true or false
What does the = operator mean in JavaScript?
the assignment operator allows for assigning a value to a variable
How do you update the value of a variable?
variable name, then equal sign, followed by new value
What is the difference between null and undefined?
- null is assigned to a variable which should be purposefully empty for now
- undefined is accidentally empty, assigned by computer when no value is provided
Why is it a good habit to include “labels” when you log values to the browser console?
helps to know where the information is coming from, helps other developers
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining strings with the plus operator
What purpose(s) does the + plus operator serve in JavaScript?
adding numbers or combining strings (concatenation)
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the result of the right side plus the left side and replaces the left side
What are objects used for?
store key/value collections of data, as well as methods relevant to that object
What are object properties?
the association between a key and a value, or the equivalent of a variable stored in an object
Describe object literal notation.
a way to initialize an object using the left curly brace and right curly brace, with optional properties nested inside
How do you remove a property from an object?
- use the delete operator to remove the property completely
- assign to empty string to remove the value only
What are the two ways to get or update the value of a property?
- dot notation: object name, dot, property key
- bracket notation: object name, brackets enclosing quotation marks enclosing property key
What are arrays used for?
arrays store lists of information
Describe array literal notation.
square brackets surrounding the data strings
How are arrays different from “plain” objects?
arrays are ordered by number, objects have property names