JavaScript Flashcards
(119 cards)
What is the purpose of variables?
Variables store data that will be used in the future
How do you declare a variable?
var variableName
var keyword + variable name
How do you initialize (assign a value to) a variable?
Assignment operator ( = )
var variableName = expression;
What characters are allowed in variable names?
all Alphanumeric characters and the underscore symbol
tip: can’t start variable names with number and recommended to not start with a capital
What does it mean to say that variable names are “case sensitive”?
Uppercased letters and lowercased letters are completely different in the case of names
var Apple is not the same as var apple
What is the purpose of a string?
String stores text data
What is the purpose of a number?
number stores number data for a mathematical expression
What is the purpose of a boolean?
Boolean is used for yes or no situations
What does the = operator mean in JavaScript?
Assignment operator ( = )
How do you update the value of a variable?
Assigning the variableName with a new expression or value
var A = 3 A = 6
variable A is now 6
What is the difference between null and undefined?
null is used when the developer intentionally wants a variable to be empty.
undefined occurs when a variable has not been assigned a value and is most oftentimes a bug in the code
Why is it a good habit to include “labels” when you log values to the browser console?
console logging “labels” makes it easier for debugging when checking through many different variables
Give five examples of JavaScript primitives.
String
Number
Boolean
Null
Undefined
What data type is returned by an arithmetic operation?
number data type
What is string concatenation?
String concatenation refers to the ( + ) in a string expression
Attaches a string value to another string value
What purpose(s) does the + plus operator serve in JavaScript?
Addition or concatenation
What data type is returned by comparing two values (, ===, etc)?
Boolean (true or false)
What does the += “plus-equals” operator do?
Addition-Assignment Operator ( += )
Adds/Concatenates the left operand with a number/string and assigns the value back to the left operand
motto += 2
motto = motto + 2
What are objects used for?
Objects are used to sort and categorize sets of data
What are object properties?
Object properties are names of each category the data will be sorted into
{
propertyName: propertyValue;
}
Describe object literal notation.
var objectName = { propertyName: propertyValue, property2Name: property2Value };
How do you remove a property from an object?
Use delete keyword to remove property from an object
var object = { property1: property1Value }; delete object.property1;
What are the two ways to get or update the value of a property?
dot notation => object.property1
bracket notation => object[‘property1’]
What are arrays used for?
Arrays are used for creating/sorting/organizing data into ordered lists