Javascript Flashcards
What is the purpose of variables?
used to store information to be referenced and manipulated in a computer program
How do you declare a variable?
with a var, let or const
How do you initialize (assign a value to) a variable?
using the assignment operator
What characters are allowed in variable names?
letters, numbers, dollar signs, nonpunctuation characters
What does it mean to say that variable names are “case sensitive”?
takes account lower or uppercase
What is the purpose of a string?
holds text characters, literal constant
What is the purpose of a number?
stores numbers…
What is the purpose of a boolean?
determines true or false
What does the = operator mean in JavaScript?
assignment operator
How do you update the value of a variable?
reassignment
What is the difference between null and undefined?
null means no value, undefined means just not defined at all
Why is it a good habit to include “labels” when you log values to the browser console?
gives a good point of reference
Give five examples of JavaScript primitives.
String, boolean, number, null and undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
operation of joining character strings end-to-end
What purpose(s) does the + plus operator serve in JavaScript?
addition and string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left
What are objects used for?
stores its state in fields
What are object properties?
Object properties are defined as a simple association between name and value
Describe object literal notation.
an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last
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?
dot or bracket notation
object.property
object[‘property’]
What are arrays used for?
ordered lists
Describe array literal notation.
square brackets [ ] with a comma between each item
How are arrays different from “plain” objects?
arrays are ordered, items are indexed, arrays will repair themselves if items are deleted, arrays have a set length
What number represents the first index of an array?
0
What is the length property of an array?
count and stores the number of items in the array
How do you calculate the last index of an array?
.length - 1;
What is a function in JavaScript?
a repeatable series of statements to accomplish an operation
Describe the parts of a function definition.
function keyword
function name
parameters
code block
Describe the parts of a function call.
name of function, (), arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call is shorter since it doesn’t have to define the function in curly braces
What is the difference between a parameter and an argument?
para: placeholders, arguments are real data
Why are function parameters useful?
dont need to use a var, great placeholder
What two effects does a return statement have on the behavior of a function?
allows users to assign the result of the function and closes the function
Why do we log things to the console?
To keep track of our progress and to verify our output
What is a method?
function that is a property of an object
How is a method different from any other function
methods are called with dot notation since they’re a property
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 of math object
How do you generate a random number?
random method of math object
How do you delete an element from an array?
pop to remove at end, splice to remove at a point, shift to remove begining
How do you append an element to an array?
push 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?
strings are immutable, can check through console.log
Is the return value of a function or method useful in every situation?
no sometimes it’s built in
Roughly how many array methods are there according to the MDN Web docs?
36
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.
> , < , >= , <= , === , and !== .
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 (condition) inside code-block
statement1
What are the three logical operators?
|| (OR), && (AND), ! (NOT).
How do you compare two different expressions in the same condition?
logical and or logical or
What is the purpose of a loop?
repeats a sequence of instructions until a specific condition is met.
What is the purpose of a condition expression in a loop?
Condition is an expression that is tested each time the loop repeats. As long as condition is true, the loop keeps running.
What does “iteration” mean in the context of loops?
Iteration is the repetition of a function or process in a computer program.
When does the condition expression of a while loop get evaluated?
Before the code-block executes
When does the initialization expression of a for loop get evaluated?
The very first action, before anything
When does the condition expression of a for loop get evaluated?
before code block, and after the code block until the condition = false.
When does the final expression of a for loop get evaluated?
after the code block after the final condition has happened.
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?
(adds one to) its operand and returns a value
How do you iterate through the keys of an object?
through a for in loops
How do you iterate through the keys of an object?
through a for in loops
Why do we log things to the console?
To see if our expected output to match
What is a “model”?
a representation of the page