JavaScript Flashcards
What is the purpose of variables?
variables give us permanents (store data to use later)
How do you declare a variable?
type the keyword var, let, const
How do you initialize (assign a value to) a variable?
use a single =
What characters are allowed in variable names?
letter, dollar sign, underscore, and numbers
What does it mean to say that variable names are “case sensitive”?
lowercase & uppercase matters in JS
What is the purpose of a string?
characters (store texts)
What is the purpose of a number?
calculations, any math related value
What is the purpose of a boolean?
potential to have logic (binary statement)
What does the = operator mean in JavaScript?
assignment operator (to put a value)
How do you update the value of a variable?
only write the variable name (without rewriting var)
What is the difference between null and undefined?
null is an assigned value. (made to be empty on purpose)
undefined means a variable has been declared but not defined yet.
Why is it a good habit to include “labels” when you log values to the browser console?
makes it easier to debug
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined, objects
What data type is returned by an arithmetic operation?
number
What is string concatenation?
addition for strings
What purpose(s) does the + plus operator serve in JavaScript?
add values or concatenate strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
allows you to add numbers or strings to an existing variable
What are objects used for?
grouping of data
What are object properties?
variables within a certain boundaries
Describe object literal notation.
variable = {
property: 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?
dot notation, bracket notation
What are arrays used for?
store set of orders
Describe array literal notation.
[ set of values stored, separated by comma ]
How are arrays different from “plain” objects?
they have orders, square brackets, not individually named
What number represents the first index of an array?
0
What is the length property of an array?
total number of items inside an array
How do you calculate the last index of an array?
subtract one from length
What is a function in JavaScript?
reusable statement for tasks
Describe the parts of a function definition.
parameter, function keyword, function code block
Describe the parts of a function call.
name of the function, parenthesis, and arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
definitions: keyword, code block, parameters
call: arguments
What is the difference between a parameter and an argument?
parameter: placeholder for argument
argument: actual value for function to be called
Why are function parameters useful?
without it, the function’s end result is always the same
What two effects does a return statement have on the behavior of a function?
- exits the code block
2. gives a value
Why do we log things to the console?
debugging tool
What is a method?
methods are functions stored into the property of an object.
How is a method different from any other function?
stored into the property of an object.
How do you remove the last element from an array?
pop method
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?
splice method
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?
they do not change the original. Check by using console.log()
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
25
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?
add conditions to the code
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if, condition, {}
What are the three logical operators?
and, or, not
How do you compare two different expressions in the same condition?
use logical and or logical or
What is the purpose of a loop?
to perform repeated task
What is the purpose of a condition expression in a loop?
if it s true, it continues, if it s false, it stops
What does “iteration” mean in the context of loops?
one repetition of the code block loop
When does the condition expression of a while loop get evaluated?
before the code block runs
When does the initialization expression of a for loop get evaluated?
very beginning (before anything)
When does the condition expression of a for loop get evaluated?
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
What does the ++ increment operator do?
increments variable by 1
How do you iterate through the keys of an object?
use a for in loop
Why do we log things to the console?
to check if the code is working, to make debugging easier
What is a “model”?
representation of something
Which “document” is being referred to in the phrase Document Object Model?
HTML doc
What is the word “object” referring to in the phrase Document Object Model?
data type in javascript
What is a DOM Tree?
model of the page when a browser loads a web page.
Give two examples of document methods that retrieve a single element from the DOM.
document.getElementById(), document.querySelector()
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
if you want to access it multiple times
What console method allows you to inspect the properties of a DOM element object?
dir method
directory
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
so that it runs after all the information on HTML document
What does document.querySelector() take as its argument and what does it return?
css selector as an argument (String)
first element in HTML doc that matches
What does document.querySelectorAll() take as its argument and what does it return?
css selector as argument
returns nodelist
Why do we log things to the console?
To check the process and values. Verifying if something actually happened.