JavaScript Flashcards
What is the purpose of variables?
the purpose of variables is to store data for future use
How do you declare a variable?
with keyword “var” and an assignment operator and value
How do you initialize (assign a value to) a variable?
with the assignment operator “=”
What characters are allowed in variable names?
letters, numbers, $, and _
What does it mean to say that variable names are “case sensitive”?
it means that
var score
and
var Score
are different
What is the purpose of a string?
to store text
What is the purpose of a number?
to store number data
What is the purpose of a boolean?
to be a light switch
it stores “true” or “false”
and is the logic in JavaScript
What does the “=” operator mean in JavaScript?
it’s the assignment operator and assigns values to variables
How do you update the value of a variable?
with the assignment “=” operator
What is the difference between “null” and “undefined”?
null is an object and intentional. a placeholder
undefined is automatically assigned to a variable
Why is it a good habit to include labels when you log values to the browser console?
to add context to what you’re doing. also makes the data easier to read
Give five examples of JavaScript primitives
null undefined string number boolean
symbol
bigint
What data type is returned by an arithmetic operation?
number
What is a string concatenation?
It’s the combination of two strings by using the “+” operator
What purpose(s) does the + operator serve in JavaScript?
it’s used as addition in arithmetic, as concatenation with strings and variables
What data type is returned by comparing two values (, ===, etc)
boolean
What does the += “plus-equals” operator do?
It adds whatever value is specified to the variable and then reassigns it to the variable
What are objects used for?
They’re used to store related data in one place
What are object properties?
Object properties serve as the “variables” of an object
Describe object literal notation
a list of key value pairs within an object
a key is assigned a value and each pair is separated by a comma
var = {
key: value,
secondKey: value
};
How do you remove a property from an object?
with the “delete” keyword
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What are variables called in an object?
they are called properties
What are the names of properties and methods called in an object?
they’re called keys
What are arrays used for?
arrays are used when storing a list of data that’s all related to each other and especially when you’re unsure of how many items you’ll be storing
Describe array literal notation
var array = [‘value1’, ‘value2’, ‘value3’];
How are arrays different from “plain” objects?
Instead of properties, they have indexes
Arrays are ordered, objects aren’t
objects ‘values’ are given property names
arrays aren’t.. they’re just indexed
What is the length property of an array?
It tells us how long an array is
How do you calculate the last index of an array?
array.length - 1
since the first index is array[0]
What is a function in JavaScript?
repeatable, named block of code that does
Describe the parts of a function definition
function keyword optional function name names for parameter list { return some work;}
Describe the parts of a function call
function keyword optional name optional parameter opening brace of function code block code optional return statement closing brace of function code block
When comparing them side-by-side, what are the differences between a function call and a function definition?
definition has a code block
call does not
definition passes parameters
call (passes arguments)
definition has function keyword
call does not
What’s the difference between a parameter and an argument?
parameters are part of a function definition
arguments are part of a function call
Why are function parameters useful?
to add context and to pass info
What two effects does a return statement have on the behavior of a function?
- ) it returns a value
2. ) it stops the function
Why do we log things to the console?
to double check our work and make sure that everything is working as intended
What is a method?
a method is a function within an object
just like how variables become properties within a function
a function stored within the property of an object
How is a method different from any other function?
a function is called by name and passed parameters
a method is called along with a object using dot-notation and can access the data in said object
How do you remove the last element from an array?
with the pop() method
array.pop()
How do you round a number to the nearest integer?
with the Math.floor() method
How do you generate a random number?
with the Math.random() method
How do you delete an element from an array?
with the splice() method
array.splice()
How do you append an element to an array?
with the push() method
array.push()
How do you break a string up into an array?
with the split() method
string.split()
Do string methods change the original string?
no, but if i wasn’t sure, i’d log to the console
Roughly how many string methods are there according to MDN Web docs?
40-ish
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to MDN?
30 ish
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
M
D
N
Give 6 examples of comparison operators
less than < less than or equal to <= greater than > greater than or equal to >= is equal to == strictly equal to === is not equal to !== is strictly not equal to !===
What data type do comparison expressions evaluate to?
booleans
What is the purpose of an if statement?
to execute an action depending on if a condition is met
allows the computer to make decisions
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement
if statement
condition (x > y)
IF condition is met, then one or more expressions is executed
ELSE a different expression is executed
return
What are the three logical operators?
&& AND, || OR, ! NOT
How do you compare two different expressions in the same condition?
by using a logical operator
What is the purpose of a loop?
to repeat a block of code many times
What is the purpose of a condition expression in a loop?
to let the loop know when to stop
What does “iteration” mean in the context of loops?
a single time that the code block of the loop runs
When does the condition expression of a while loop get evaluated?
before the code is ran
before each iteration
When does the initialization expression of a for loop get evaluated?
before the condition
before the loop runs
When does the condition expression of a for loop get evaluated?
after the initialization
and before each iteration
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;