JavaScript Flashcards
What is the purpose of variables?
to store values/information
and we are able to refer/call this variable later!
i.e to store information for the future
How do you declare a variable?
use keyword (“var”, “let”, “const”)
followed with the name of variable and end with semicolon “;”
ex) var name;
How do you initialize (assign a value to) a variable?
single equal sign (assignment operator)
start with variable name following with an equal sign (=) and the value you want to assign to variable. end with semicolon
ex) Name = “Monique”;
- but usually will declare and assign variable in one step!!
ex) var Name = “Monique”;
What characters are allowed in variable names?
numbers, letters, dollar sign ($), underscore (_)
**but variables cannot start with numbers!!!
What does it mean to say that variable names are “case sensitive”?
lowercase and uppercase letters are different (even if its same letter)
(ex) Name, name –> are two different variable names
What is the purpose of a string?
to store letters and other characters
a sequence of a set of characters
js wont care about what is in strings
What is the purpose of a number?
to store numeric values
(that we usually do calculations with, mathematical operations)
financial information a good example to use numbers but not smt like a zipcode (b/c we arent usually doing mathematical operations with zipcode values)
What is the purpose of a boolean?
purpose is to make decisions
it is able to represent if something is or isn’t (binary)
What does the = operator mean in JavaScript?
assignment operator
used to assign a value to a variable
assign: to store information to a variable (name)
How do you update the value of a variable?
don’t use keyword!! (if variable already exists)
write variable name with equal sign (assignment operator) and new variable value
What is the difference between null and undefined?
both are value types
null: value that is assigned and purposely/intentionally left blank/empty
value that can only appear b/c DEVELOPER purposely assigned it to something
ex) optional inputs on a website from user (we still need to store data about user, so can use null in the optional inputs user did not fill out)
undefined: value that is assigned by BROWSER
value that can come from anywhere; if undefined pops up, need to investigate?
Why is it a good habit to include “labels” when you log values to the browser console?
to give clarity
to know if the correct value is being assigned to correct variables (debugging or double checking when you go back to code)
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adding two or more strings together to create one string
(addition but for strings)
*concatenation does not change the value of the individual strings”
What purpose(s) does the + plus operator serve in JavaScript?
mathematical operations (summing), string concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
shorthand operator
adds a value to an already existing variable and reassigns the resulting value to the same variable
ex) var name = “Monique”;
name += “ Chang”;
name variable's value would now be Monique Chang, and not Monique
What are objects used for?
to group together data, functions, etc that are related to each other
create multiple groups of organized data
(are able to use same property names for multiple objects)
What are object properties?
individually named data inside objects
(are variables essentially)
Describe object literal notation.
object name = { };
object name = {
property name: property value,
property name: property value,
property name: property value
};
*example of key/value pair
How do you remove a property from an object?
use delete.”object name”
delete operator
What are the two ways to get or update the value of a property?
use dot notation or bracket notation
objectname.objectpropertyname/key
objectname[“objectpropertyname.key”]
*bracket notation wont work for methods!
*bracket notation useful b/c in dot notation, js perceives anything after dot as a string
so variables, numbers etc cant work with dot notation.
. notation code reading
[ ] notation code reading
. = “of”
[ ] = “at”