JavaScript Flashcards
What is the purpose of variables?
To store bits of data that the computer needs in order to do its tasks
How do you declare a variable?
with the keyword “var” followed by the identifier or variable name
How do you initialize (assign a value) to a variable?
with the assignment operator (=)
What characters are allowed in variable names?
letters of the alphabet, dollar sign ($), underscore, numbers (can’t start with number)
What does it mean to say that variable names are “case sensitive”?
e.g. the variables “test” and “Test” are different.
What is the purpose of a string?
sequence of characters that represent text
What is the purpose of a number?
represents a numeric data type that allows us to perform mathematical operations on it
What is the purpose of a boolean?
logical data type that only returns true or false. Useful for conditionals. Lets the computers ultimately decide what to do or not do.
What does the = operator mean in JavaScript
assignment operator. Assigns the value of the right to whatever is on the left.
How do you update the value of a variable?
the assignment operator can update the value of a variable. var keyword not necessary to update value
What is the difference between null and undefined?
undefined: JavaScript’s method of saying “empty”
null: developer’s way of saying “empty”; assigned intentionally
Why is it a good habit to include “labels” when you log values to the browser console?
Shows the user which logs represent which values. Logs without labels can cause confusion
Give five examples of JavaScript primitives
string, number, bigint, boolean, undefined, symbol, null
primitive: data that is not an object and has no methods. primitives can NOT be altered
What data type is returned by an arithmetic operation?
number
What is string concatenation?
using + to join together multiple things into a single string
What purposes does the plus (+) operator serve in JavaScript?
- addition
- string concatenation
What data type is returned by comparing two values (< , > , ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds/concatenates the value on the right with the value on the left and then assigns it to the variable on the left.
What are objects used for?
to group relevant data together
What are object properties?
variables that live within an object
Describe object literal notation
declare a variable and assign it a value of a curly brace block. The contents of the curly brace block can be empty or consist of key, value pairs
How do you remove a property from an object?
Using the delete operator
delete object.property
What are the two ways to get or update the value of a property?
dot notation (object.property = value)
bracket notation (object[‘property’] = value)
What are arrays used for?
Useful when working with lists or groups of similar data