JavaScript Flashcards
What is the purpose of variables?
To remember data for future reference.
How do you declare a variable?
Write down keyword (var) to declare that variable.
How do you initialize (assign a value to) a variable?
By using a single = sign, (= meaning assignment).
What characters are allowed in variable names?
Letters, $, _ anywhere and numbers ,but number needs to be at the end.
What does it mean to say that variable names are “case sensitive”?
JavaScript does not consider lowercase and uppercase the same.
What is the purpose of a string?
A way to hold a sequence of characters represented with letter characters.
What is the purpose of a number?
To store numbers for calculation.
What is the purpose of a boolean?
It allows us to render what is or isn’t.
What does the = operator mean in JavaScript?
To assign a thing.
How do you update the value of a variable?
No keyword is necessary.
What is the difference between null and undefined?
Null can only be assigned and not generated by JavaScript, undefined comes from JavaScript.
Why is it a good habit to include “labels” when you log values to the browser console?
To know what you are looking at specifically.
Give five examples of JavaScript primitives.
String, number, boolean, null, and undefined.
What data type is returned by an arithmetic operation?
A number.
What is string concatenation?
Any type of values being added to a string which results in one string.
What purpose(s) does the + “plus” operator serve in JavaScript?
It can concatenate or be used for addition.
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
It adds the value to the variable and assigns that result to the variable.
What are objects used for?
To group together a set of properties, variables and functions to give it grouping in one location.
What are object properties?
The piece of data represented by the key and value.
Describe object literal notation?
The data inside the {} for example: properties or key and values.
How do you remove a property from an object?
With the delete operator and . name of the property
What are the two ways to get or update the value of a property?
You can use dot notation or bracket notation.
What are arrays used for?
Good for rendering a list of data of any length and where the order is important or unimportant.
Describe array literal notation.
Opening bracket and closing bracket with any number of data types inside the array.
How are arrays different from “plain” objects?
All arrays have a length property while objects do not.
What number represents the first index of an array?
Number 0.
What is the length property of an array?
True count of how many items are in that array.
How do you calculate the last index of an array?
Subtract 1 from the length property of an array.
What is a function in JavaScript?
To group a series of statements together to preform a specific task.
Describe the parts of a function definition.
Function, name for the function, parameters in a set of (), and a code block {}.
Describe the parts of a function call.
Function name ().
When comparing them side-by-side, what are the differences between a function call and a function definition?
There is no code block in a call and the function keyword.
What is the difference between a parameter and an argument?
Arguments are values provided when a function is called and parameter are values provided when a function is defined.
Why are function parameters useful?
Parameters take in values and place them inside the function so that you can reuse the function instead of making multiple set of code for each value
What two effects does a return statement have on the behavior of a function?
stops the function entirely and gives you a value to wherever the function is called
Give 6 examples of comparison operators.
> (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to), === (strictly equal), and !== (strictly not equal to)
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
It allows us to make a choice
Is else required in order to use an if statement?
no it is not
Describe the syntax (structure) of an if statement.
start with if then parenthesis and curly braces then your return statement inside then a else or else/if statement with a return
What are the three logical operators?
&& (and), || (or), ! (not)
How do you compare two different expressions in the same condition?
using &&, or ||
Why do we log things to the console?
to debug and see whats going on or to better understand what is happening
What is a method?
function which is the value of an object stored
How is a method different from any other function?
methods are attributed to an object and called by attaching a dot ( . ) to the object while function you can just call
How do you remove the last element from an array?
by using the .pop method that goes off an array object
How do you round a number down to the nearest integer?
the floor method takes it down to the nearest integer
How do you generate a random number?
the random method for the object math
How do you delete an element from an array?
the splice method for the array object with the argument index number to know where to delete from
How do you append an element to an array?
the push method of the array object to add it to the end of an array
How do you break a string up into an array?
the split method of the string with the argument string space (‘ ‘)
Do string methods change the original string? How would you check if you weren’t sure?
it does not change the string and you can check by using the log method for the console object
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
What is the purpose of a loop?
to repeat a block of code until a condition is no longer met
What is the purpose of a condition expression in a loop?
the condition is there to stop the loop when it is not met
What does “iteration” mean in the context of loops?
one time the code block in the loop runs
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated?
from the beginning and just once
When does the condition expression for a for loop get evaluated?
after the initialization and before each iteration of the code block
When does the final expression of a for loop get evaluated?
at the end of each iteration, the final expression is what continues the loop
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break is how you escape a loop, break is used when you are looking for one value
What does the ++ increment operator do?
increases the value by 1
How do you iterate through the keys of an object?
using for in loop
What is the event.target?
element you are interacting with
What is the effect of setting an element to display: none?
makes element not visible, but still exists (no longer part of the flow or have no visual appearance)
What does the element.matches() method take as an argument and what does it return?
takes css selector and returns a boolean and whether the element matches the selector
How can you retrieve the value of an element’s attribute?
getAttribute(name of attribute) method
At what steps of the solution would it be helpful to log things to the console?
every new line of code or expression
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
you would have to have an individual conditional for each view and tab
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
What is JSON?
text-based data format following JavaScript object syntax
What are serialization and deserialization?
serialization is converting data into a stream of bytes and deserialization is the opposite
Why are serialization and deserialization useful?
serialization sends data easily while deserialization converts back that data back to an object so that it is easy to work with
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify() method
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parce() method
How do you store data in localStorage?
localStorage.setItem(name(keyName), value(keyValue)) method
How do you retrieve data from localStorage?
localStorage.getItem(keyName) method
What data type can localStorage save in the browser?
string data
When does the ‘beforeunload’ event fire on the window object
when the window, the document and its resources are about to be unloaded or when the page closes (close page, refresh page, or)
In JavaScript, when is scope determined?
when it parses the code
What allows JavaScript functions to “remember” values from their surroundings?
a closure
What values does a closure contain?
all variables and functions within the closures parent scope
When is a closure created?
everytime a function reference is created and captured at run time
How can you tell if a function will be created as a closure?
if it needs any variables outside of itself
In React, what is one important case where you need to know if a closure was created?