JavaScript Flashcards
What is the purpose of variables?
To store data that needs to be referenced later
How do you declare a variable?
Using the keyword var (const and let)
How do you initialize (assign a value to) a variable?
var variableName = value;
What characters are allowed in variable names?
Letters, numbers, $, _ (numbers cannot be first)
What does it mean to say that variable names are “case sensitive”?
They are sensitive to uppercase and lowercase letters
What is the purpose of a string?
Store a series of character, text content
What is the purpose of a number?
To store a numeric value, counting, measurement, math
What is the purpose of a boolean?
A data type that only has two possible values, to make decisions
What does the = operator mean in JavaScript?
Assigning a value to something
How do you update the value of a variable?
variableName = newValue
What is the difference between null and undefined?
Null: empty value, must be assigned by you, it represents something that does not have a value assigned to it yet,
Undefined: empty value, assigned by JavaScript
Where is var scoped
Var is scoped to the function that it is inside of. If you leave out the var keyword when using a variable in a function, JavaScript will look for the next variable that is scoped closest
Why is it a good habit to include “labels” when you log values to the browser console?
So you know what is being logged to the console
Give five examples of JavaScript primitives.
String, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
Combining a string with another value and makes the result of that expression into a new string
What purpose(s) does the + plus operator serve in JavaScript?
Adding numbers, concatenating strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Adds the value of the variable on the right to the variable on left, then assigns the result of that expression to the variable on the left
What are objects used for?
Storing data in a group or collection that makes sense
What are object properties?
Pieces of data stored within an object
Describe object literal notation.
Var variableName = {};
How do you remove a property from an object?
The delete operator: delete object.property
What are the two ways to get or update the value of a property?
Dot notation: object.propertyName
Bracket notation: object[‘propertyName’]