JavaScript Flashcards
What is the purpose of variables?
It allows the program to store values
How do you declare a variable?
Begin with the keyword var followed by the variable’s name
How do you initialize (assign a value to) a variable?
Use “=” to set the variable equal to the value
What characters are allowed in variable names?
Any letters, numbers, “$”, and “_”
What does it mean to say that variable names are “case sensitive”?
Casing changes the name of a variable
What is the purpose of a string?
To represent text values
What is the purpose of a number?
To represent numerical values used in calculation and indexing
What is the purpose of a boolean?
To represent logic values
What does the = operator mean in JavaScript?
It means to assign a value
How do you update the value of a variable?
Assign the variable with the new value
What is the difference between null and undefined?
Null is still considered an object while undefined is not
Why is it a good habit to include “labels” when you log values to the browser console?
It gives more clarity to the console, which is helpful for debugging
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?
When two or more strings are combined to make a new string that is a combination of the original strings
What purpose(s) does the + plus operator serve in JavaScript?
It is both the arithmetic operator for addition and the concatenation operator for strings
What data type is returned by comparing two values (> ,< , ===, etc)?
boolean
What does the += “plus-equals” operator do?
It applies the + operator to the values on either side of the += and assigns the result to the variable on the left
What are objects used for?
They group together variables and functions to create a model of a real-world entity
What are object properties?
An object’s variables; a key/value pair
Describe object literal notation.
You define the object in curly braces {}, separate properties with commas, and define key/value pairs using a colon to separate them
How do you remove a property from an object?
Use the keyword delete followed by the object
What are the two ways to get or update the value of a property?
Dot notation object.key or bracket notation object[‘key’]
What are arrays used for?
Arrays are used for listing items