JavaScript Flashcards
What is the purpose of variables?
Allows you to store data and access them later.
How do you declare a variable?
- variable keyword
- variable name
- assignment operator (=)
- variable value
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letters, digits, _, $, and it cannot start with a number
(ex: cat1 is okay but not 1cat)
What does it mean to say that variable names are “case sensitive”?
uppercase and lowercase matters in JavaScript.
(ex. JavaScript != javascript)
precision is mandatory
What is the purpose of a string?
Storing some sequence of characters
What is the purpose of a number?
Stored when we need to manipulate mathematical information
What is the purpose of a boolean?
It is important for conditions. Able to represent if something is or isn’t.
Their purpose is to make decisions.
What does the = operator mean in JavaScript?
It is the assignment operator.
Used to assign a value to a variable.
How do you update the value of a variable?
When updating, you do not need the variable keyword, but still need the assignment operator.
+=
What is the difference between null and undefined?
undefined ==> a value that is not actually there. Means empty
null ==> null is a value that is assigned. It is done on purpose.
Why is it a good habit to include “labels” when you log values to the browser console?
Having labels makes it clear what we are working with.
Sometimes, there are multiple console.logs and you would need to differentiate.
Give five examples of JavaScript primitives.
- String
- Numbers
- Booleans
- Null
- Undefined
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
The process of joining together two or more strings to create one new string. Uses the + (plus operator)
What purpose(s) does the + plus operator serve in JavaScript?
The plus operator can be used for string concatenation and as an arithmetic operation (adding).
What data type is returned by comparing two values (<, >, ===, etc)?
A boolean
(true or false)
What does the += “plus-equals” operator do?
The += is an assignment operator that sums up the left and right operand values then assign the obtaining result to the left operand.
It will increment your sum variable with the amount next to it.
What are objects used for?
Objects group together a set of variables and functions to create a model of something you would recognize from the real world
What are object properties?
If a variable is part of an object, it is called a property. Properties tell us about the object, such as the name of a hotel or the number of rooms it has.
Describe object literal notation.
The object is the curly braces and their contents. Separate each key from its value using a colon. Separate each property and method with a comma (but not after the last value).
How do you remove a property from an object?
Use the delete operator and assign the property using either the dot or bracket notation.
What are the two ways to get or update the value of a property?
Dot notation and bracket notation.
Ex. student.firstName || student[‘firstName’]
What are arrays used for?
Arrays store a list of values.
You should consider using an array whenever you are working with a list or a set of values that are related to each other.