Week 2 Quiz Questions Flashcards
What is the purpose of variables?
Variables are used to store temporary data (esp in scripts)
How do you declare a variable?
Variable syntax:
var nameOfVariable = “string”
with var
How do you initialize (assign a value to) a variable?
Variable syntax:
var nameOfVariable = “string”
with the equals sign (assignment operator)
What characters are allowed in variable names?
letters, dollar signs, underscores, numbers.
cannot start with a number
What does it mean to say that variable names are “case sensitive”?
Upper and Lower case changes the variable you are using:
camelCase and camelcase would be different variables.
What is the purpose of a string?
stores text data
What is the purpose of a number?
used in counting/ calculating sums
What is the purpose of a boolean?
has a value of true or false
What does the = operator mean in JavaScript?
assignment operator used when assigning variables to a value
How do you update the value of a variable?
declare the variable again (without var) and put the updated value on the other side of the assignment operator
What is the difference between null and undefined?
null- variable that has no value
undefined- variable that has just been declared and doesnt have a value YET
Why is it a good habit to include “labels” when you log values to the browser console?
Shows user which variable/ object/ data type they are logging to the console. for neatness and clarity
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined.
*
and <style> similarities*</style>
CSS should be written in css files and console.log/js functions should be written in the js file
generally shouldnt (need to) write code within <style> and
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining two or more strings (or other primitive data types) into a new string that has both values combined
What purpose(s) does the + plus operator serve in JavaScript?
in both arithmetic with numbers and string concatenation.
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 value to that same variable
What are objects used for?
objects store sets of data (properties: keys and values, and methods: keys and functions)
What are object properties?
a variable that is stored in an object (key: value pairs)
Describe object literal notation.
var object = {
key: value
}
How do you remove a property from an object?
with ‘delete’:
delete object.property
What are the two ways to get or update the value of a property?
can be used with either dot notation (object.dot) or bracket notation (object[“bracket”])
What are arrays used for?
stores a (ordered) list of values (numbers, booleans, strings, arrays, objects)
Describe array literal notation.
var array = [‘one’, 2, false]
How are arrays different from “plain” objects?
Arrays, by nature, are ordered lists (and numerically indexed)
What number represents the first index of an array?
0 (zero)
What is the length property of an array?
Returns a numeric value of how many elements are in the array.
array.length = (some number)