JavaScript Flashcards
What is the purpose of variables?
variables are used to store data/information to be used in scripts/functions
How do you declare a variable?
var variableName;
How do you initialize (assign a value to) a variable?
variableName = variableValue;
using the assignment operator
What characters are allowed in variable names?
Must start with letter, $, or _. Can contain letters, numbers, $’s, or _’s.
What does it mean to say that variable names are “case sensitive”?
name and Name are not the same variable
What is the purpose of a string?
Strings can be used for names, usernames, messages, etc. that need to be displayed.
What is the purpose of a number?
Numbers are used for mathematical functions, counting, positioning on a screen, etc.
What is the purpose of a boolean?
Booleans display values of true or false.
What does the = operator mean in JavaScript?
The = operator is used to assign a value to a variable.
How do you update the value of a variable?
By setting a new value to the variable name using the = operator.
What is the difference between null and undefined?
Null can be used as a placeholder value for a variable as it is still an object.
Undefined is when no value has been assigned to a variable yet.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels make it more clear the reason that something is being logged to the console, or what the value being logged represents.
Helps with debugging.
Give five examples of JavaScript primitives.
String, number, boolean, null, and undefined.
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
pushing two string values together into one string value
What purpose(s) does the + plus operator serve in JavaScript?
addition of numbers or concatenation of strings
What data type is returned by comparing two values (<, >, ===, etc)?
boolean values
What does the += “plus-equals” operator do?
adds a value on the right to the variable on the left, then assigns the new value to that same variable
What are objects used for?
Grouping together sets of variables and their values as well as methods, typically a set of traits describing a real-world object.
What are object properties?
variables stored within an object
Describe object literal notation.
variableName = {
property: value,
property: value
};
How do you remove a property from an object?
using the delete operator
delete objectName.objectProperty
What are the two ways to get or update the value of a property?
dot notation
objectName.objectProperty = propertyValue;
bracket notation
objectName[‘objectProperty’] = propertyValue;
What are arrays used for?
storing lists of values under a variable name