JavaScript Flashcards
What is the purpose of variables?
assign values
How do you declare a variable?
use var, let, const
How do you initialize a variable?
equal sign
What characters are allowed in variables names?
must begin with a letter, dollar sign, or underscore
can contain numbers but cannot use a dash or period
cannot use keywords or reserved words
case sensitive
What dose it mean to say that variable names are case sensitive?
if two variables are spelled the same way but have different casing, then js treats them as two different variables
What is the purpose of a string?
to store characters
What is the purpose of a number?
to store numbers
What is the purpose of a boolean?
to store something as true or false
What does the = equals sign operator mean in JS
assign a variable
How do you update the value of a variable?
you use the equal sign operator again
What is the difference between null and undefined?
a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address
a variable is undefined when a value is not assigned to it
Why is it a good habit to include labels when you log values to the browser console?
This will allow you to see if what you are storing is good and makes sense
Give five examples of JavaScript primitives
string, number, boolean, undefined, symbol, null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining strings together
What purpose(s) does the + plus operator serve in JS?
addition, incrementing, concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equal” operator do?
adding or concatenating something to itself
What are objects used for?
store multiple types of data
What are object properties?
object properties are the keys of data that are stored in an object
Describe object literal notation
declare a variable, assignment operator, curly brackets
How do you remove a property from an objects?
use delete function
What are the two ways to get or update the value of a property?
dot and bracket notation
What are arrays used for?
ordered lists and groupings of information
Describe array literal notation
square brackets
How are arrays different from plain objects?
ordered, use index
What number represents the first index of an array?
0
What is the length property of an array?
can be called to find the length of the array
How do you calculate the last index of an array?
array.length-1
What two effects does a return statement have on the behavior of a function?
returns a value and exits code block
Why are function parameters useful?
allows functions to run with certain values
What is the difference between a parameter and an argument?
parameter is for defining, argument for calling
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition has function keyword and {}
Describe the parts of a function call.
function call consists of function name and parentheses and possible arguments
Describe the parts of a function definition.
function keyword, function name, parentheses, possible parameters, {}
What is a function in JavaScript?
code that can be repeated over and over again easily
Why do we log things to the console?
so that we can see that things are being input correctly
What is a method?
a function that is a property of an object
How is a method different from any other function?
functions themselves are objects, so a method is actually an object reference to a function
How do you remove the last element from an array?
pop method
How do you round a number down to the nearest integer?
floor method
How do you generate a random number?
random method
How do you delete an element from an array?
splice method
How do you append an element to an array?
push or unshift (prepend) method
How do you break a string up into an array?
split method
Do string methods change the original string? How would you check if you weren’t sure?
mdn, console log, they do not
Roughly how many string methods are there according to the MDN Web docs?
a lot
Roughly how many array methods are there according to the MDN Web docs?
a lot
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
there is the equal to, less than, greater than, strictly equal to, less than or equal to, and greater than or equal to
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
to make a decision
Is else required in order to use an if statement?
no
Describe the syntax of an if statement
if statement, () with conditionals inside, {} with rule to run if conditions are met
What are the three logical operators?
logical and, logical or, logical not
How do you compare two different expressions in the same condition?
use logical and or logical or
When does the condition expression of a while loop get evaluated?
after the initialization, and at the beginning of every loop