JavaScript Flashcards
What is the purpose of variables?
To store data types to later recall that information.
How do you declare a variable?
With var, let, const.
How do you initialize (assign a value to) a variable?
With an assignment operator (=).
What characters are allowed in variable names?
They can contain letters, numbers, dollar signs, or an underscore, but numbers cannot be the first character.
What does it mean to say that variable names are “case sensitive”?
Variable names are different if they have different letters capitalized or lower cased.
What is the purpose of a string?
Strings can be used when working with any kind of text.
What is the purpose of a number?
To be able to give a variable a numeric data type for math.
What is the purpose of a boolean?
To state whether a variable is true or false in order to compare.
What does the = operator mean in JavaScript?
It means to assign a value to a variable. For the variable to contain or hold this value.
How do you update the value of a variable?
You assign it to a different value.
What is the difference between null and undefined?
It is a value that is purposely left ambiguous and generally leads to an object. Undefined values are variables that do not have a value.
Why is it a good habit to include “labels” when you log values to the browser console?
The console can display exactly what it is being logged.
Give five examples of JavaScript primitives.
Exercise
Numbers, strings, boolean, null, and undefined.
What data type is returned by an arithmetic operation?
The result of the mathematical operation is returned and contained in the variable, which is numeric.
What is string concatenation?
It is the process of joining together two or more strings and containing it in a variable.
What purpose(s) does the + plus operator serve in JavaScript?
It can add two number values together and it can concatenate two strings.
What data type is returned by comparing two values (, ===, etc)?
A boolean data type is returned, either true or false.
What does the += “plus-equals” operator do?
The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable. (Example: motto = motto + “ is the GOAT”)
What are objects used for?
Objects group together a set of variables and functions to create and organize a model of something. To create subdivision of an object.
What are object properties?
Properties tell us about the object like details. They are key-value pairs.
Describe object literal notation.
Objects are the properties and values within the curly braces and it is stored in a variable. So, it is a set of key-value pairs within curly braces being assigned to a variable. Properties are separated by colons and split by commas.
How do you remove a property from an object?
By using the delete keyword followed by the object name and property name separated by a dot.
What are the two ways to get or update the value of a property?
You can use either the dot notation or square brackets enclosing a set of quotation marks surrounding the property value.
What are arrays used for?
To store a list of similar data.
Describe array literal notation.
A set of values encased in square brackets separated by commas, assigned to a ‘var’ keyword and the variable name.
How are arrays different from “plain” objects?
Arrays are set ordered, they are indexed numerically, there is a constant count of the values in it.
What number represents the first index of an array?
By [0].
What is the length property of an array?
It is the length or number of values in an array.
How do you calculate the last index of an array?
name of the object.length subtracted by 1.