javascript Flashcards
What is the purpose of variables?
used to store information to be referenced and manipulated
How do you declare a variable?
by using the var keyward
How do you initialize (assign a value to) a variable?
by adding an equal sign to the right of the variable name
What characters are allowed in variable names?
The period, the underscore, and the characters $, #, and @
What does it mean to say that variable names are “case sensitive”?
it means that names need to be identical
What is the purpose of a string?
used for data values that are made up of ordered sequences of characters
What is the purpose of a number?
to give a number value to a variable
What is the purpose of a boolean?
to assign true or false to a variable
What does the = operator mean in JavaScript?
to assign
How do you update the value of a variable?
by reassigning it
What is the difference between null and undefined?
null is set but undefined is a return value set by javaScript
Why is it a good habit to include “labels” when you log values to the browser console?
to identify which console log belongs to which.
Give five examples of JavaScript primitives.
string, null, numbers , undefined boolean
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
adding 2 strings together
What purpose(s) does the + plus operator serve in JavaScript?
addition
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds and assign
What are objects used for?
Objects group together a set of variables and functions
What are object properties?
a simple association between name and value
Describe object literal notation.
an array of key:value pairs
How do you remove a property from an object?
by using the delete operator
What are the two ways to get or update the value of a property?
by dot notation and bracket notation
What are arrays used for?
to store more then one information at a time
Describe array literal notation.
where you define a new array using just empty brackets
How are arrays different from “plain” objects?
Objects represent properties while arrays create and store list of data in a single variable
What number represents the first index of an array?
0
What is the length property of an array?
.length
How do you calculate the last index of an array?
length - 1
What is a function in JavaScript?
a set of statements that performs a task or calculates a value
Describe the parts of a function definition.
a set of inputs, a set of outputs, and a rule that relates the elements of the set of inputs to the elements
Why are function parameters useful?
because they allow storing data that the function needs to work with
What two effects does a return statement have on the behavior of a function?
the return statement returns the values inside the function then anything after the return statement will not run.
Describe the parts of a function call.
arguments: an array-like object containing the argument passed to the currently executing function
callee: the currently executing function.
caller: the function that invoked the currently executing function.
length: the number of arguments passed to the function
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function call is invoking or calling that function a function definition is defining the function
What is the difference between a parameter and an argument?
function parameters are names listed in the function’s definition. arguments are the real values passed to the function.
Why do we log things to the console?
to see the code output
What is a method?
a method is a function which is a property of an object.
How is a method different from any other function?
method is associated with an object
How do you remove the last element from an array?
by using the pop() method
How do you round a number down to the nearest integer?
by using the method Math.floor()
How do you generate a random number?
by using the math.random method
How do you delete an element from an array?
by using the splice() method
How do you append an element to an array?
by using the push or the unshift method
How do you break a string up into an array?
by using the split method
Do string methods change the original string? How would you check if you weren’t sure?
they don’t modify the original string. the way to check it is by using console.log
Roughly how many string methods are there according to the MDN Web docs?
around 50
Is the return value of a function or method useful in every situation?
yes
Roughly how many array methods are there according to the MDN Web docs?
around 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.
===, !== , < , >, <=, >=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
decision-making statement that guides a program to make decisions based on specified criteria
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if keyward, conditoin, then the code to run if value is true
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
by using a logical operator
What is the purpose of a loop?
to repeats a sequence of instructions until a specific condition is met