JavaScript Flashcards
What is the purpose of variables?
Store data, information in variables
Data can change (vary) each time a script runs
How do youdeclarea variable?
var variableName;
Keywords: var, let, const
How do you initialize (assign a value to) a variable?
variableName = value;
= : assignment operator
What characters are allowed in variable names?
Must begin with a: letter, $, or _
can contain numbers (numbers CANNOT start variable name)
What does it mean to say that variable names are “case sensitive”?
Declare different variables depending on upper or lower case usage:
score vs. Score
What is the purpose of a string?
To store text, letters and other characters
Enclosed within a pair of quotes
Frequently used to add new content into a page and they can contain HTML markup
What is the purpose of a number?
To store numerical data
Calculate, determine size of screen, move position of an element on a page, set the amount of time an element should take to fade in
What is the purpose of a boolean?
Boolean data types store one of two values: true or false
Purpose: Make decisions
Used like a switch: on or off
Helpful when determining which part of a script should run
What does the=operator mean in JavaScript?
Assignment operator: used to assign a value to a variable
How do you update the value of a variable?
variable = newValue;
Keyword is only necessary when declaring a new variable
What is the difference betweennullandundefined?
Null is an assigned value, purposefully designated empty by developer while Undefined is returned by the browser
Null: represents a reference that points, generally intentionally, to a nonexistent or invalid object or address
Undefined: 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?
Helpful to identify what you are logging to the console
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
bigint, symbol
(7 total)
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
Process of joining together two or more strings to create one new string
What purpose(s) does the+plus operator serve in JavaScript?
Adds one value to another
Sums numerical data or string concatenation
What data type is returned by comparing two values (<,>,===, etc)?
Boolean
What does the+=”plus-equals” operator do?
Addition assignment: Adds the value of the right operand to a variable and assigns the result to the variable
What are objects used for?
Group together a set of variables and functions to create a model of something
What are object properties?
Variables that are part of an object
Describe object literal notation.
var object = {
key: value,
propertyName: value,
key: function() {
}
};
How do you remove a property from an object?
Delete operator
delete object.property;
What are the two ways to get or update the value of a property?
Dot notation using member operator (.)
object.propertyName = newValue;
Square bracket syntax
object[‘propertyName’] = newValue;
What are arrays used for?
Store a list of variables and set of values that are related to each other
Group together like data