JavaScript Flashcards
What is the purpose of variables?
Storing values under a specific name and stores data to be called upon when needed
How do you declare a variable?
Creating the variable with the keywords let const or var and giving it a name
How do you initialize (assign a value to) a variable?
Using the assignment operator(=) giving the variable a value
What characters are allowed in variable names?
Letter dollar sign or underscore, can’t start with numbers
What does it mean to say that variable names are “case sensitive”?
That variables name like score and Score are different variable names
What is the purpose of a string?
Storing a set of characters.
What is the purpose of a number?
handles numeric data types for mathematical operations
What is the purpose of a boolean?
Denote true or false, represents is or isn’t. Make decisions.
What does the = operator mean in JavaScript?
It means a variable is being assigned to a value.
How do you update the value of a variable?
You must assign the variable a new value, and not use the keyword since the variable already exists. var is only used for the first time.
What is the difference between null and undefined?
null is assigned by the developer purposefully! and means it does not exist. undefined is assigned by the browser and free to use.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels describe the value or variable being logged, makes it clear what your working when you come back to the code
Give five examples of JavaScript primitives.
Boolean, int, string, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Combines two string values together using the add operator, never changes the original makes a new string.
What purpose(s) does the + plus operator serve in JavaScript?
summing numerical data or concantenation
What data type is returned by comparing two values (<, >, ===, etc)?
Booleans, true or false
What does the += “plus-equals” operator do?
Adds the right operand to the variable and assigns the new value to the variable.
What are objects used for?
To group together a set of variables and function
What are object properties?
A variable that is inside of an object
Describe object literal notation.
Var name assignment operator(=) { ((object literal)
Properties and values seperates by : and commas separating those
};
How do you remove a property from an object?
Delete variablename.nameofproperty
What are the two ways to get or update the value of a property?
Variablename followed by period variable.propertyname or variablename[‘property’]
What are arrays used for?
to store a list of values as a variable that are USUALLY alike, and iterate through them one ate a time if needed
Describe array literal notation.
var name = [‘string’, false, 3132];
How are arrays different from “plain” objects?
arrays are a special type of object. they have key value pairs like normal objects but the key for each value in an array is its index number. you can also know the number of pieces of data with array.length. also can add additional information with the push method
What number represents the first index of an array?
0
What is the length property of an array?
the number of items in the array array.length
How do you calculate the last index of an array?
var lastIndex= arrayname.length - 1
arrayname[lastindex]
how does one acesss an array in an object
nameofarray. propertyname.arrayname[index position]
cost. rooms1.items[0]
how does one access an object in an array
costs[2].propertyname
could also be costs[2].products[0.author
What is a function in JavaScript?
a block of code that is named and accomplishes a task
Describe the parts of a function definition.
function keyword, optional name (parameter list with optional parameters) {
optional return statement
}
Describe the parts of a function call.
function name ( arguments optional ) invoked by the parantheses.
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition is the defining the code and the keyword and calling it is to actually run the code block in the defintion with parentheses and arguments
What is the difference between a parameter and an argument?
a parameter is placeholder in a function definition, an argument is what a function is called with
Why are function parameters useful?
parameters gives us muteability (ability to change) the function.
What two effects does a return statement have on the behavior of a function?
it exits the code block and also produces a value we can use in our program
Why do we log things to the console?
so that we can check our returned value, debugging tool
What is a method?
a method is a function that is a property of an object
How is a method different from any other function?
methods are associated with objects, functions are not
How do you remove the last element from an array?
.pop() removes the last element and returns it
How do you round a number down to the nearest integer?
math.floor() returns nearest integer that is less than or equal to given number
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice(index position, number of items)
How do you append an element to an array?
push() adds the elements to the end of an array
How do you break a string up into an array?
split()
Do string methods change the original string? How would you check if you weren’t sure?
No they do not, console.log(stringname) strings are immutable
Roughly how many string methods are there according to the MDN Web docs?
a lot
Is the return value of a function or method useful in every situation?
no example pop method
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.
===, >, <, >=, <=, !=
What data type do comparison expressions evaluate to?
booleans. true and false
What is the purpose of an if statement?
to check a condition true or false whether to run a certain code block
Is else required in order to use an if statement?
no it is not
Describe the syntax (structure) of an if statement
if keyword ( condition ) { code block }
What are the three logical operators?
&& and, !! or !not
How do you compare two different expressions in the same condition?
logical operators || &&
What is the purpose of a loop?
offer. a quick way to do something repeatedly, repeat functionality
What is the purpose of a condition expression in a loop?
a conditional expression in a loop signifies a decision to either execute the code block if condition is met or stop
for loop parts
inital expression, conditional statement,
code block
final expression
What does “iteration” mean in the context of loops?
each time the code inside the block is run
When does the condition expression of a while loop get evaluated?
before it executes the code block
When does the initialization expression of a for loop get evaluated?
before anything, one time
When does the condition expression of a for loop get evaluated?
after the initialization, before the code block, and after the final expression
When does the final expression of a for loop get evaluated?
after the code block executes and before the condition runs again
Besides a return statement, which exits its entire function block, which keyword
break;
What does the ++ increment operator do?
incremenes by 1 and adds it to the variable and reassigns to the variable