JavaScript Flashcards
What is the purpose of variables?
The purpose of variables is to store a value.
How do you declare a variable?
A variable is declared with the const, var, or let keyword along with a name. e.g. ‘var test’.
How do you initialize (assign a value to) a variable?
To initialize a variable you use the = operator. e.g. ‘var test = ‘test’ ‘.
What characters are allowed in variable names?
The characters used must be a letter, underscore, or $.
What does it mean to say that variable names are “case sensitive”?
Variables are distinguished by their capitalization. e.g. ‘var Test’ and var test’ are different variables.
What is the purpose of a string?
A string is used to store a sequence of characters.
What is the purpose of a number?
A number is used to store numeric values.
What is the purpose of a boolean?
A boolean is used to store a true/false value.
What does the = operator mean in JavaScript?
The = operator is the assignment operator. It assign a value to a variable.
How do you update the value of a variable?
To update a variable you call the variable along with a new value. e.g. ‘test = ‘hi’.
What is the difference between null and undefined?
The Null type is purposely defined, while undefined is typically accidental.
Why is it a good habit to include “labels” when you log values to the browser console?
Adding labels to console log makes it easier to distinguish where the value is coming from.
Give five examples of JavaScript primitives.
The JavaScript primitives are: Number, String, Boolean, undefined, BigInt, and Symbol.
What data type is returned by an arithmetic operation?
Numeric data is returned by an arithmetic operation.
What is string concatenation?
String concatenation is joining strings by using the + operator. e.g. ‘var test = ‘hi ‘ + ‘name’ will return ‘hi name’.
What purpose(s) does the + plus operator serve in JavaScript?
The + operator is used for concatenation along with addition.
What data type is returned by comparing two values (, ===, etc)?
The data type returned by comparison operators is a boolean. e.g. true/false
What does the += “plus-equals” operator do?
The += operator adds both sides of an assignment together before assigning. e.g. var test = 1, var hello = 1 test += hello is now equal to '2'.
What are objects used for?
Objects are used to store multiple values.
What are object properties?
Object properties are the names of their values. e.g. ‘number: 2’.
Describe object literal notation.
A variable declaration followed by an object literal its containing properties, that are separated by commas, and a closing literal. e.g. var object = { property: ‘value’ }
How do you remove a property from an object?
To remove a property from an object the ‘delete’ operator would be used. e.g. ‘delete object.property’.
What are the two ways to get or update the value of a property?
To get/update a property you can use either bracket or dot notation. e.g. object.property or object[‘property’].
What are arrays used for?
Arrays are used to store multiple values.