JavaScript 0130 Flashcards
What is the purpose of variables?
*To have a place to store data to be used later
How do you declare a variable?
using an assignment operator, e.g. “var”, and naming it within the confines of naming. it does not need to be initialized/assign to be declared
How do you initialize (assign a value to) a variable?
initialize is assign. use “=” and then assign its value
What characters are allowed in variable names?
$ _ letters numbers
What does it mean to say that variable names are “case sensitive”?
e.g. fullname and fullName are two different variables
What is the purpose of a string?
for text content
What is the purpose of a number?
store numbers to be used for things like calculation
What is the purpose of a boolean?
for decision making
What does the = operator mean in JavaScript?
it is used for declaring varables
How do you update the value of a variable?
type its name, then “=”, then the new value
What is the difference between null and undefined?
und var is not defined, null is like a placeholder
Why is it a good habit to include “labels” when you log values to the browser console?
so you can distinguish them in the console
Give five examples of JavaScript primitives.
number, string, bulion, undefined, null
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
joining data (strings?) with the + operator
What purpose(s) does the + plus operator serve in JavaScript?
to add numbers in calculations, to join data thru concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
a boolean
What does the += “plus-equals” operator do?
it adds
What are objects used for?
for storing data with descriptions, or keys/objects
What are object properties?
a variable becomes a property in an object
Describe object literal notation.
you create an object by using “var”, e.g., “=”, then “{“, so:
var person = {name: colin, hobby: cycling}
How do you remove a property from an object?
use the delete keyword, e.g. “delete person.name”
What are the two ways to get or update the value of a property? (give two examples of updating and two of getting)
bracket and dot notation, e.g.:
console.log(person.name)
console.log(person[name])
person.name = “colin”
person[“name”] = “colin”
what’s another word for “property” in objects?
a property can be called a key, and with a value is called a “key value pair”