JavaScript Flashcards
What is the purpose of variables?
To store variable data in short-term memory. They can be used to represent values in scripts that are likely to change
How do you declare a variable?
By using a variable keyword(var, let, const) followed by the variable name(identifier)
How do you initialize (assign a value to) a variable?
By using the assignment operator (=) after the variable name followed by the variable value you want to assign to the variable
What characters are allowed in variable names?
Names can contain letters, numbers, dollar sign ($), or an underscore (), but may only begin with a letter, dollar sign ($), or and underscore ()
What does it mean to say that variable names are “case sensitive”?
It means that it would recognize the two names “variable” and “Variable” as different names
What is the purpose of a string?
Strings contain letters and other characters and can be used when working with any kind of text. They’re frequently used to add new content into a page and they can contain HTML markup
What is the purpose of a number?
Numbers are for numerical values, including negative numbers and decimals, and are also used for tasks like calculators, determining the size of the screen, moving the position of an element on a a page, or setting the amount of time an element should take to fade in
What is the purpose of a boolean?
a boolean can only hold two values: true or false and are helpful when determining which part of a script should run
What does the = operator mean in JavaScript?
The equals (=) sign is an assignment operator. It says that you are going to assign a value to the variable. It is also used to update the value given to a variable
How do you update the value of a variable?
The assignment operator can also be used to update the value given to a variable
What is the difference between null and undefined?
a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address while undefined is a value automatically assign to variables that have only been declared, or to formal arguments for which there are no actual arguments. Though they are both marked as one of the primitive values, when using the typeof operator, null returns “object”
Why is it a good habit to include “labels” when you log values to the browser console?
By including a short string that describes the variable or value being logged, it is helpful when debugging
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null, bigint, symbol
What data type is returned by an arithmetic operation?
number
What is string concatenation?
“Adding” strings together, one following the other in order
What purpose(s) does the + operator serve in javascript?
The + operator serves as both the arithmetic operator for addition of numbers as well as for adding strings with concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
boolean (true or false)
What does the += “plus-equals” operator do?
The += operator adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator. Addition or concatenation is possible
What are objects used for?
Objects group together a set of variables and functions to create a model of a something you would recognize from the real world
What are object properties?
An object property is a variable part of an object which tell us more about the object
Describe object literal notation.
Object literal notation is the easiest and most popular way to create objects where you define an object with a curly braces assigned to a variable
How do you remove a property from an object?
Remove a property from an object using the “delete” keyword
What are the two ways to get or update the value of a property?
dot notation (object.property) and bracket notation (object[‘property’])
What are arrays used for?
Arrays are for storing a list or a set of values that are related to each other
Describe array literal notation.
It is the preferred method for creating an array when you create an array and give it a name using the var keyword followed by the name of the array and then assign the values to the array inside a pair of square brackets with each value separated by a comma
How are arrays different from “plain” objects?
arrays are indexed starting at 0 and objects have named keys for properties
What number represents the first index of an array?
0 (array[0])
What is the length property of an array?
.length (array.length)
How do you calculate the last index of an array?
array[array.length-1]