JAVASCRIPT Flashcards
What is the purpose of variables?
store data
How do you declare a variable?
var let const
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
number, letter, underscore, $
What does it mean to say that variable names are “case sensitive”?
lowercase and uppercase matters
What is the purpose of a string?
store letters
What is the purpose of a number?
store numerical data
What is the purpose of a boolean?
true/false used to make decisions
What does the = operator mean in JavaScript?
assign
How do you update the value of a variable?
reassign a new value
What is the difference between null and undefined?
undefined: no value assigned
null: set to nothing
Why is it a good habit to include “labels” when you log values to the browser console?
to know what you are actually logging
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining strings
What purpose(s) does the + plus operator serve in JavaScript?
addition of numbers and concatenation of strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
assigns the value of the variable to the previous value plus right-side of operator
What are objects used for?
store multiple types of data that are related
What are object properties?
variables glued to objects
Describe object literal notation.
{key: value}
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
object.property (dot notation)
object[‘property’] (square bracket notation)
What are arrays used for?
store data in order
Describe array literal notation.
var array = [ ]
How are arrays different from “plain” objects?
numeric indexes vs named properties
arrays have order
What number represents the first index of an array?
0
What is the length property of an array?
number of items in the array
How do you calculate the last index of an array?
[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.
- function keyword
- optional name
- zero or more parameters in ( ) separated by commas
- code block { }
- optional return statement inside code block
Describe the parts of a function call.
- functions name
2. zero or more arguments in ( ) separated by commas
When comparing them side-by-side, what are the differences between a function call and a function definition?
function calls do not have code blocks or keyword
What is the difference between a parameter and an argument?
parameters are placeholders in a function definition
arguments are actual data in a function call
Why are function parameters useful?
reusability and variability
What two effects does a return statement have on the behavior of a function?
causes the function to produce a value
also exits the function; no code after the return statement is executed
Why do we log things to the console?
so we can keep track of our data as we change it
What is a method?
a function
How is a method different from any other function?
function which is a property of an object, static and instance
How do you remove the last element from an array?
array.pop( )
How do you round a number down to the nearest integer?
Math.floor( )
How do you generate a random number?
Math.random( )
How do you delete an element from an array?
array. pop( ) end
array. shift( ) start
array. splice( ) anywhere
How do you append an element to an array?
array. push( ) end
array. unshift( ) start
How do you break a string up into an array?
string.split( )
Do string methods change the original string? How would you check if you weren’t sure?
no. log to console before and after method
Is the return value of a function or method useful in every situation?
no
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?
to make decisions
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condition) {codeblock}
What are the three logical operators?
&&AND ||OR !NOT
How do you compare two different expressions in the same condition?
$$ ||
What is the purpose of a loop?
to repeat the same, or similar, code a number of times
What is the purpose of a condition expression in a loop?
to stop the loop
What does “iteration” mean in the context of loops?
each time the loop runs
When does the condition expression of a loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated?
once, when the loop begins
When does the final expression of a for loop get evaluated?
after each iteration
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
increments (adds one to) its operand and returns a value
How do you iterate through the keys of an object?
for in loop
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
defined
What allows JavaScript functions to “remember” values from their surroundings?
closures