JavaScript Flashcards
what is the purpose of variables?
store data for reuse
how do you declare a variable?
var
how do you initialize (assign a value to) a variable?
var x = ‘string’;
what characters are allowed in variable names?
letters, numbers, $, _
however must start with letter, $, or _.
must not use - or .
what does it mean to say that variable names are “case sensitive”
the slightest capitalization difference for the same word will count as different variables
what is the purpose of string?
used when working with any kind of text
what is the purpose of a number?
for tasks that involve counting or calculating sums
what is the purpose of boolean?
helpful when determining which part of a script should run/ acts as an on or off switch
what does the = operator mean in javascript?
assignment operator
how do you update the value of a variable?
use the variable name, the equals sign, and the new value
what is the difference between null and undefined?
null represents a reference that points to a nonexistent or invalid object or address
undefined is a value 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?
easier to keep track of console output for yourself and others
give five examples of javascript primitives
string, number, boolean, undefined, null
what data type is returned by an arithmetic operation?
number
what is string concatenation?
placing string together to form a single output of string
what purpose(s) does the + plus operator serve in JS?
concatenation and addition
what data type is returned by comparing two values (,===, etc)?
boolean
what does the += plus-equals operator do?
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 to create a model of something you would recognize from the real world
what are object properties?
exclusive variables - another way to store data
describe object literal notation
assigning the object properties within { }
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
use dot or bracket notation
what are arrays used for?
when you are working with a list or a set of values that are related to each other