LFZ JS Quiz Flashcards
What is the purpose of variables?
To store information
How do you declare a variable?
with the var keyword
How do you initialize (assign a value to) a variable?
with the assignment operator =
What characters are allowed in variable names?
$, _
What does it mean to say that variable names are “case sensitive”?
Capitalization matters
What is the purpose of a string?
to store an array of characters
What is the purpose of a number?
to store a number or float
What is the purpose of a boolean?
to store true or false
What does the = operator mean in JavaScript?
it is the assignment operator
How do you update the value of a variable?
assign the variable to another value with the assignment operator
What is the difference between null and undefined?
null is an empty object while undefined is nothing
Why is it a good habit to include “labels” when you log values to the browser console?
For clarity in debugging
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining two stings together into one
What purpose(s) does the + plus operator serve in JavaScript?
to add numbers or concatenate strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the result with itself
What are objects used for?
To group together a set of variables and functions
What are object properties?
the object’s variables
Describe object literal notation.
assign a var to an object by putting the object inside curly braces
How do you remove a property from an object?
using the delete keyword
What are the two ways to get or update the value of a property?
using dot notation or bracket notation
What are arrays used for?
To store data, mainly lists
Describe array literal notation.
var foo = []
How are arrays different from “plain” objects?
Stores data with index value as the keys
What number represents the first index of an array?
0
What is the length property of an array?
the amount of values it has
How do you calculate the last index of an array?
subtract 1 from the length method of the array object
What is a function in JavaScript?
A group of code that can be reused and called with arguments
Describe the parts of a function definition.
the name, the parameters, the code
Describe the parts of a function call.
the name, the arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call just needs the function name and arguments. A function definition uses the function keyword and has code.
What is the difference between a parameter and an argument?
a parameter is like a temporary variable that takes in input, while the arguments are the input
Why are function parameters useful?
Pass data into the function
What two effects does a return statement have on the behavior of a function?
the return statement breaks out of the function and returns the value
Why do we log things to the console?
For debugging
What is a method?
A function that is the property of an object
How is a method different from any other function?
It is apart of an object and is called using dot notation or bracket notation
How do you remove the last element from an array?
using the pop method of the array object
How do you generate a random number?
using the random method of the Math object
How do you delete an element from an array?
using the splice method of the array object
How do you append an element to an array?
using the push method of the array object
How do you break a string up into an array?
using the split method of the array object
Do string methods change the original string? How would you check if you weren’t sure?
No they do not, you can check the documentation
Roughly how many string methods are there according to the MDN Web docs?
~50
Is the return value of a function or method useful in every situation?
No
Roughly how many array methods are there according to the MDN Web docs?
~50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
, <=, >=, ==, ===
Give 6 examples of comparison operators.
, <=, >=, !==, ===
What data type do comparison expressions evaluate to?
Boolean
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if keyword, expression, and codeblock