JavaScript Flashcards
What is the purpose of variables?
The purpose of variables is to “remember”/store values/information. (Used to represent values in your scripts that are likely to change.)
How do you declare a variable?
Use the var keyword before the name of the variable
How do you initialize (assign a value to) a variable?
Use the equal sign assignment operator
What characters are allowed in variable names?
The name can contain letters, numbers, a dollar sign ($), or an underscore (_), but it must not start with a number.
What does it mean to say that variable names are “case sensitive”?
A variable name with lowercase letters will not be the same as the same variable name with uppercase. (eg. score and Score would be different variable names),and it is bad practice to create two variables that have the same name using different cases.
What is the purpose of a string?
To assign/store alphanumeric values as a text value to a variable
What is the purpose of a number?
To store numeric characters and allow us to do mathematical calculations.
What is the purpose of a boolean?
Booleans give/represent a true or false value
What does the = operator mean in JavaScript?
It is an assignment operator used to assign a value to a variable.
How do you update the value of a variable?
Just use the variable name and assign the new value for that attribute.
What is the difference between null and undefined?
A null value is intentionally created to be empty (represents a reference that typically points to a nonexistent or invalid object or address). Undefined is empty by nature and is automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
To add clarity to the output, in particular to aid in debugging.
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined, bigint, symbol
What data type is returned by an arithmetic operation?
A numeric value
What is string concatenation?
Two or more strings joined with the string operator (+).
What purpose(s) does the + plus operator serve in JavaScript?
The plus operator is used for addition with numerical values and for string concatenation, joining strings on either side of it.
What data type is returned by comparing two values (, ===, etc)?
A boolean value will be returned
What does the += “plus-equals” operator do?
The “Plus-Equals” (addition assignment) operator takes the original value of the variable and concatenates with a new variable, then reassigns itself back to the original variable.
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?
They are variables that tell us about the object. (Expressed in key:value pairs)
Describe object literal notation.
var varName = { property:"value", property:"value", property:"value", };
How do you remove a property from an object?
Use the Delete keyword and then use dot notation to identify the property or method you want to remove from the object.
What are the two ways to get or update the value of a property?
By using the dot notation or square brackets → object.property_name = ‘(new)property_value’; or object[‘property_name’] = ‘(new)property_value’;
What are arrays used for?
Lists or sets of values that are related to each other, anything that is numerically indexed
Describe array literal notation.
Var variable_name = [a, b, c, d]
Var keyword with the name of the variable followed by the equals assignment operator, a square bracket containing the values, followed by a closing square bracket
How are arrays different from “plain” objects?
The key for each value is its index number