JavaScript Flashcards
What is the purpose of variables?
To temporarily store data needed to run scripts
How do you “declare” a variable?
Using the keyword var
var variableName = variableValue
How do you “initialize” (assign a value to) a variable?
= (assignment operator)
What characters are allowed in variable names?
Letters, $, _
What does it mean to say that variable names are “case sensitive”?
Uppercases matter: tom is different than Tom
What is the purpose of a string?
To assign any text value
What is the purpose of a number?
Used for counting / calculating
What is the purpose of a boolean?
Gives true or false, helps determine which script to run
What does the |=| operator mean in JavaScript?
Assignment operator
How do you update the value of a variable?
variableName = newValue
What is the difference between |null| and |undefined|?
Null represents an invalid or nonexistent object, undefined represents no value
Why is it a good habit to include “labels” when you log values to the browser console?
To help with debugging and know which functions you are working with
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined
What data type is returned by an arithmetic operative?
Number
What is string concatenation?
Combining strings and numbers together for a longer string
What purpose(s) does the |+| plus operator serve in JavaScript?
Concatenation and adding values
What data type is returned by comparing two values?
Booleans
What does the |+=| “plus-equals” serve in JavaScript?
Adds value of the right side to a variable and assigns result to said variable
What are objects used for?
To create a model of something recognizable from the real world by grouping together a set of variables and functions
What are object properties?
Variables that are part of the object
Describe object literal notation.
var objectName = {
key: value, };
How do you remove a property from an object?
delete objectName.propertyName;
What are the two ways to get or update the value pf a property?
dot notation or square brackets
What are arrays used for?
When you are working with a list or set of values related to each other.
Describe array literal notation.
var arrayName = [‘string’, value, …, ‘string’];
How are arrays different from “plain” objects?
Arrays use index numbers for the key for each value.
What number represents the first index of an array?
Zero
What is the |length| property of an array?
arrayName.length