JavaScript Flashcards
What is the purpose of variables?
to store data that can later be used when called upon.
create permanence in data
How do you declare a variable?
var variableName
How do you initialize (assign a value to) a variable?
variableName = value;
What characters are allowed in variable names?
letters
numbers (can’t start the variable name)
underscore
dollar sign
What does it mean to say that variable names are “case sensitive”?
fullName and FullName are two different variables
What is the purpose of a string?
used when working with any kind of text
a set of characters in a row that javascript won’t care about
What is the purpose of a number?
mathematical operations
What is the purpose of a boolean?
hold true/false data types
helpful when determining which part of a script should run
What does the = operator mean in JavaScript?
assignment operator
stores value to a variable
How do you update the value of a variable?
variableName = new value;
What is the difference between null and undefined?
undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments. (automatic assignment from the browser)
null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address. (null only exists because its been ASSIGNED–> purposeful)
Why is it a good habit to include “labels” when you log values to the browser console?
So you know what data you’re looking at.
Sometimes, it’s helpful to put more than one console.log() in your code to help you debug.
Give five examples of JavaScript primitives.
string
number
boolean
undefined
null
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
adding two strings together
What purpose(s) 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?
The addition assignment operator (+=) adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
objects group together a set of variables and functions that are related to each other
What are object properties?
variables that are part of objects. They tell us about the object
Describe object literal notation.
you create an object by declaring the variable and assigning its properties and their corresponding values inside of curly brackets or instead use empty curly brackets and add properties later
ex)
var hotel = {
name: ‘Quay’,
rooms: 40,
booked: 25,
}
How do you remove a property from an object?
delete object.property;
What are the two ways to get or update the value of a property?
dot notation
object.propertyName = propertyValue;
square bracket notation
object[‘propertyName’] = propertyValue;
What are arrays used for?
group similar data types together by storing values in a list