Javascript Flashcards
(174 cards)
What is the purpose of variables?
Used to store data
How do you declare a variable?
var keyword + variable name
How do you initialize a variable?
By using the assignment operator ( = ) and giving it value
What characters are allowed in variable names?
Letters, numbers, dollar signs, and underscores
What does it mean to say that variable names are “case-sensitive”
Uppercase and lowercase variables with the same name will have different values
What is the purpose of a string?
Used to store data of letters and words.
Used to add new content into a page
Can contain HTML markup
What is the purpose of a number?
Used for calculations or tasks such as determining size of screen, moving the position of an element on a page, or setting the amount of time an element should take to fade it
What is the purpose of a boolean?
Helpful in determining which part of a script should run
What does the = operator mean in javascript?
the assignment operator.
states that you are going to assign value to a variable
How do you update the value of a variable?
Reassign it.
Variable name + equal sign +new value
What is the difference between null and undefined?
Null is an assigned value (means nothing)
Undefined means a variable has been declared but not yet defined
Null is an object, undefined is undefined
Why is it a good habit to include labels when you log values to the browser console?
For clarity - to keep your code clean and help you fix issues
Give 5 examples of javascript primitives:
- String
- Number
- Boolean
- Undefined
- Null
What data type is returned by an arithmetic operation?
Numbers
What is string concatenation?
Adding two strings together with the + symbol
What purpose does the + operator serve in javascript
Addition with numbers, concatenation with strings or strings & numbers
What data type is returned by comparing two values ( ‘ > ‘, ‘ < ‘ , === ,etc)?
Boolean
What does the += “plus equal” operator do
assigns the value of the right operand to a variable and assigns the result to the variable
x+=5 is the same as x= x+5
What are objects for?
Grouping together a set of variables and functions to create a model of something
Objects store related data
What are object properties?
The variables of the object
collection of key: value pairs
Describe object literal notation
Key value pairs that are separated from each other with a colon and separated from other properties and methods with a comma and then stored in a variable inside curly braces
How do you remove a property from an object?
delete keyword followed by object name period and property name
delete object.property
What are the two ways to get or update the value of a property?
dot notation: var name = object.newproperty bracket: var name = object['property']
What are arrays used for?
storing lists or sets of values