JavaScript Flashcards
What is the purpose of variables?
to store data
How do you declare a variable?
variable keyword, variable name, assignment operator, and value
ex: var name = ‘Ashley’;
How do you initialize (assign a value) to a variable?
use the assignment operator (=)
variable keyword variable name = value
var greeting = ‘hello’;
What characters are allowed in variable names?
letters, numbers, $ or underscore
** however, variables cannot start with a number
What does it mean to say that variable names are “case sensitive”?
Capitalization is taken into consideration when naming or calling variables
*means that two variables with the same name but different capitalization would be considered two variables
ex: var potato; vs var Potato;
What is the purpose of a string?
store/manipulate text that js won’t interpret as code
What is the purpose of a number?
represent and manipulate quantities/mathematical operations
What is the purpose of a boolean?
represents true/false, for decision making
What does the = operator mean in JavaScript?
a value is being assigned to a variable
How do you update the value of a variable?
use the variable name with assignment operator (=) and the new value
What is the difference between null and undefined?
Null indicates an intentional absence of a value, like a placeholder
*when you see null, that tells you that someone wanted it to be empty on purpose
undefined means there hasn’t been anything assigned to the variable
*JS way of communicating that there’s nothing there.
Why is it a good habit to include ‘labels’ when you log values to the browser console?
it provides you with more clarity and can help with debugging
Give 5 examples of JavaScript primitives
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
Numbers
What is string concatenation?
joins two or more strings together
What purpose(s) does the + operator serve in JS?
adds values together
*arithmetically if numbers
*concatenation if strings
What data type is returned by comparing two values (> < ===, etc)?
boolean
what does the += operator do?
takes the value to the right of the operator and adds/concatenates it to the variable on the left and assigns the result of that expression to the variable
What are objects used for?
to group together variables and functions to create a model of something
Gives you ability to store multiple pieces of data under 1 name
What are object properties?
variables and their values
describe object literal notation
variable keyword name of object assignment operator
curly brace followed by properties and methods and their values
end curly brace
ex: var person {
name: ‘ashley’,
age: 29,
ethnicity: ‘vietnamese’
};
How do you remove a property from an object?
delete operator followed by objectname.propertyname;
or
delete operator followed by objectname[‘property.name’];
What are two ways to get or update the value of a property?
dot notation
ex: objectname.propertyname;
bracket notation
ex: objectname.[‘propertyname];
if you want to update the value, follow it with an assignment operator and the new value
What are arrays used for?
To store a list of values that are related to each other