JavaScript Basics Flashcards
What is the purpose of variables?
To store and re-use data
How do you declare a variable?
Using the var, const, or let keyword followed by the name of the variable
How do you initialize (assign value to) a variable?
Using the var, const, or let keyword followed by the name of the variable followed by an assignment operator followed by a value
What characters are allowed in variable names?
Letters, numbers, period, underscore, dollar sign
The first character of a variable name cannot be a number
What doesit mean to say that variable names are “case sensitive”?
You can only use the exact matching name of a variable as a value for anything
What is the purpose of a string?
Allows you to create strings of characters
What is the purpose of a number?
It allows you to hold numeric value and perform calculations
What is the purpose of a boolean?
To use True or False values, such as conditionals
What does the = operator mean in JavaScript?
It’s the assignment operator
How do you update the value of a variable?
Without declaring the variable, assign the variable a new value
What is the difference between null and undefined?
Undefined means a value does not exist
Null is an assigned value that was used intentionally
Why is it a good habit to include “labels” when you log values to the browser console?
It makes debugging easier when you know the value of what variable the console.log is returning
Give five examples of JavaScript primitives
String, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
Numeric value
What is string concatenation?
Combining two or more string values
What purpose(s) does the + plus operator serve in JavaScript?
It either adds numbers or concatenates strings
What data type is returned by comparing two values (, ===, etc)?
Boolean, True or False
What does the += “plus-equals” operator do?
It adds (or concatenates) the current variable and a value, then assigns the result to the 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 ar eobject properties?
Object properties are variables
Properties can be functions, referred to as Methods
Describe object literal notation
An object is a set of opening and closing curly braces and their content, known as key value pairs
Key value pairs need to be separated by a colon, and end in a comma (Unless it’s the last key value pair of the object)
How do you remove a property from an object?
Using the delete operator before the dot notation or bracket notation for the object.property
What are two ways to get or update the value of a property?
Using dot notation or bracket notation for the object property
To update, use the assignment operator before the new value
What are arrays used for?
To hold related value as a list