Javascript p1 Flashcards
variables to loops
What is the purpose of variables?
temporarily store data
How do you declare a variable?
var, let, const
How do you initialize (assign a value to) a variable?
= assignment operator
What characters are allowed in variable names?
letters, numbers, $ and _
What does it mean to say that variable names are “case sensitive”?
same var name in upper and lowercase are two dif variables
What is the purpose of a string?
to manage text data
What is the purpose of a number?
to manage numeric data
What is the purpose of a boolean?
to work with true/false, yes/no, on/off states
What does the = operator mean in JavaScript?
assignment, this var is that value
How do you update the value of a variable?
reassign it
What is the difference between null and undefined?
- undefined has been declared and is unused (empty field)
- - null is intentionally empty
Why is it a good habit to include “labels” when you log values to the browser console?
so you know exactly what you’re looking at
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined, symbol, bigint
What data type is returned by an arithmetic operation?
numeric
What is string concatenation?
combining strings using the + operator
What purpose(s) does the + plus operator serve in JavaScript?
- combining the values it’s between
- - arithmatic & string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
combines given values and reassigns to original variable
code read: var area = width * height;
there’s the expression width * height, and the result of that expression is being assigned to the variable area
code read:
motto += ‘ is the goat’;
the string ‘ is the goat’ is being concatenated with the variable motto and the result is being reassigned to the variable motto
What are objects used for?
- creating models of things
- conceptualizing an idea of a thing by listing it’s attributes as properties/keys with values, so that information about it can be accessed or manipulated
What are object properties?
the variables that make up the object
Describe object literal notation.
– declare var name, assign it to curbrace enclosed list of comma-separated key:value pairs
var object = { property/key: 'value', property/key: 'value', }
How do you remove a property from an object?
- delete object.property/key;
- - delete object[‘property’];
What are the two ways to get or update the value of a property?
- object.property = ‘newValue’; (dot notation)
- - object[‘property’] = ‘newValue’; (square bracket syntax)
code read:
var object = {
property: value
}
there is a new object literal being assigned the variable object, with the property property assigned the value value
What are arrays used for?
storing a list of values
Describe array literal notation.
var array = [item01, item02, item03];