JavaScript Flashcards
What is the purpose of variables?
Javascript-primitives-and-variables
To store information/data.
How do you declare a variable?
Javascript-primitives-and-variables
You write var, let, or const; the name of the variable; and an assignment operator.
How do you initialize (assign a value to) a variable
Javascript-primitives-and-variables
You use an equal sign
What characters are allowed at the start of variable names?
Javascript-primitives-and-variables
$, underscore, and letters.
What does it mean to say that variable names are “case sensitive”?
(Javascript-primitives-and-variables)
A variable with a capital is different than a variable without one.
What is the purpose of a string?
Javascript-primitives-and-variables
To store text content data.
what is the purpose of a number?
Javascript-primitives-and-variables
For data that needs numbers.
What is the purpose of a boolean?
Javascript-primitives-and-variables
To give us a choice between true or false.
What does the = operator mean in JavaScript
Javascript-primitives-and-variables
It means assignment operator.
How do you update the value of a variable?
Javascript-primitives-and-variables
You assign the variable a different value.
What is the difference between null and underfined?
Javascript-primitives-and-variables
Null is for values that the coder can change later.
Undefined could be on an accident
Why is it a good habit to include “labels” when you log values to the browser console?
(Javascript-primitives-and-variables)
To prevent confusion
Give five examples of JavaScript primitives.
Javascript-primitives-and-variables
String, array, object, integer, boolean, null, undefined.
What data type is returned by an arithmetic operation?
Javascript-operators-and-expressions
Numbers.
What is string concatenation?
Javascript-operators-and-expressions
The joining of two or more strings together using the plus operator.
What purpose(s) does the + plus operator serve in JavaScript (Javascript-primitives-and-variables)
It adds numbers and joins strings together.
What data type is returned by comparing two values (, ===, etc)?
(Javascript-operators-and-expressions)
A boolean.
What does the += operator do?
Javascript-operators-and-expressions
It adds the variable and anything else and assigns the result of the expression to that variable.
What are objects used for?
Javascript-objects
Store related info for easy access later
What are object properties?
Javascript-objects
They are attached to objects to define their characteristics.
Describe object literal notation.
Javascript-objects
Curly-braces , {}
How do you remove a property from an object?
Javascript-objects
Use the delete operator on the property of the object.
What are the two ways to get or update the value of a property?
(Javascript-objects)
By using the dot method and giving it a different value or changing it in the object literal.
What are arrays used for?
Javascript-arrays
Storing related information in a specific order.
Describe array literal notation.
Javascript-arrays
Brackets, []
How are arrays different from “plain” objects?
Javascript-arrays
They store information in a specific order.
What number represents the first index of an array?
Javascript-arrays
0
What is the length property of the array?
Javascript-arrays
The number of elements in the array or string.
How do you calculate the last index of an array?
Javascript-arrays
You do array[array.length - 1]
What is a function in JavaScript?
Javascript-functions
Self contained modules of code that accomplish a specific task.
Describe the parts of a function definition.
Javascript-functions
Function, optional name, parameter, code block, optional return.
Describe the parts of a function call.
Javascript-functions
Sometimes a function keyword, sometimes a name, opening/closing parenthesis with a parameter sometimes in them, sometimes a arrow function operator, sometimes a curly bracket, a code block and sometimes a return statement within that code block.
When comparing them side-by-side, what are the differences between a function call and a function definition?
(Javascript-functions)
Function calls have opening/closing parenthesis and their value is that of their return value. Function definitions are only being defined and don’t have a value until called.
What is the difference between a parameter and an argument?
Javascript-functions
parameters are temporary. Arguments are the values you’re actually using.
Why are function parameters useful?
Javascript-functions
To prevent confusion and so you know exactly what type of argument should go in there
What two effects does a return statement have on the behavior of a function?
(Javascript-functions)
It returns the value and ends the function call immediately.
Why do we log things to the console?
Javascript-method
To check our values and make sure they are correct.
What is a method
Javascript-method
A function that is a property of an object.
How is a method different from any other function?
Javascript-method
Method’s are stored on an object
How do you remove the last element from an array?
Javascript-method
.pop() method
How do you round a number down to the nearest integer?
Javascript-method
Math.floor
How do you generate a random number?
Javascript-method
Math.random
How do you delete an element from an array?
Javascript-method
Use the .splice() method
How do you append an element to an array?
Javascript-method
.push() method
How do you break a string up in to an array?
Javascript-method
.split() method
Do string methods change the original string? How would you check if you weren’t sure?
(Javascript-method)
They do not. console.log
Roughly how many string methods are there according to the MDN Web docs?
(Javascript-method)
A LOOOOOT
Is the return value of a function or method useful in every situation?
(Javascript-method)
No, it’s not always used
Roughly how many array methods are there according to the MDN Web docs?
(Javascript-method)
A LOOOOOT
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
(Javascript-method)
MDN
Give 6 examples of comparison operators.
Javascript-if
&&, ===, !==, ||, <=, >=, %
What data type do comparison expressions evaluate to?
Javascript-if
Boolean.
What is the purpose of an if statement?
Javascript-if
They allow code to only execute under certain conditions.
Is else required in order to use an if statement?
Javascript-if
No
Describe the syntax (structure) of an if statement.
Javascript-if
if statement, conditional statement, and conditional code block
What are the three logical operators?
Javascript-if
&&, ||, and !
How do you compare two different expressions in a conditional statement?
(Javascript-if)
&&, ||, or !
What is the purpose of a loop?
Javascript-loops
To repeat a process until conditions are met.
What is the purpose of a condition expression in a loop?
Javascript-loops
To repeat the loop until certain conditions are met.
What does “iteration” mean in the context of loops?
Javascript-loops
Every time the code gets executed.
When does the condition expression of a while loop get evaluated?
(Javascript-loops)
Before each iteration.
When does the initialization expression of a for loop get evaluated?
(Javascript-loops)
At the start of the loop.
When does the condition expression of a for loop get evaluated?
(Javascript-loops)
Before each iteration block.
When does the final expression of a for loop get evaluated?
Javascript-loops
After the conditional block.
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
(Javascript-loops)
Break statement.
What does the ++ increment operator do?
Javascript-loops
It increases the variable by 1
How do you iterate through the keys of an object?
Javascript-loops
For, in loop
Why do we log things to the console?
dom-querying
To check our values and make sure they’re correct.
What is a “model”?
dom-querying
The representation of something without being it.
Which “document” is being referred to in the phrase Document Object Model?
(dom-querying)
HTML doc
What is the word “object” referring to in the phrase Document Object Model?
(dom-querying)
Data
What is a DOM Tree?
dom-querying
A JavaScript object model that holds elements and their attributes, text, and children.
Give two examples of document methods that retrieve a single element from the DOM.
(dom-querying)
querySelector(), getById(),
Give one example of a document method that retrieves multiple elements from the DOM at once.
(dom-querying)
querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
(dom-querying)
To easily change it’s value later.
What console method allows you to inspect the properties of a DOM element object?
(dom-querying)
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
(dom-querying)
HTML content needs to load before the script.
What does document.querySelector() take as its argument and what does it return?
(dom-querying)
It takes a string css selector as it’s argument and returns the first selector it finds.
What does document.querySelectorAll() take as its argument and what does it return?
(dom-querying)
It takes a string css selector as it’s argument and returns a nodelist.
Why do we log things to the console?
dom-events
To check our values and make sure they’re correct.
What is the purpose of events and event handling?
dom-events
So you can create a reaction to something the user does.
Are parameters required to use a JavaScript method or function?
(dom-events)
No, some are optional.
What method of element objects lets you set up a function to be called when a specific type of event occurs?
(dom-events)
addEventListener
What is a callback function?
dom-events
When a function is passed into another or in general as a variable.
What object is passed into an event listener callback when the event fires?
(dom-events)
An object that contains all the data from the event that happened.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
(dom-events)
The element the event occurred on. console.log(). MDN
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
(dom-events)
First one passed the function definition (correct).
Second one the return value is replacing the function.
What is the className property of element objects?
dom-manipulation
It’s their class names. That of which you can focus on and change.