JavaScript Flashcards
What is the purpose of variables?
to hold values
How do you declare a variable?
var let const
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
$_ letters and numbers
What does it mean to say that variable names are “case sensitive”?
casing matters
What is the purpose of a string?
for storing and manipulating text
What is the purpose of a number?
math
What is the purpose of a boolean?
to show true or false
What does the = operator mean in JavaScript?
assign
How do you update the value of a variable?
the variable name = new value
What is the difference between null and undefined?
null have a value while undefined does not
Why is it a good habit to include “labels” when you log values to the browser console?
to keep track of what you are logging
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining 2 strings into one +=
What purpose(s) does the + plus operator serve in JavaScript?
addition
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
addition -> assignment
What are objects used for?
to store data in an unordered list type structure
What are object properties?
variables, but for objects
Describe object literal notation.
var newObject = { };
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
What are arrays used for?
To store data of the same type together in the same place
Describe array literal notation.
[]
How are arrays different from “plain” objects?
they have a numbered index
What number represents the first index of an array?
0
What is the length property of an array?
how long the array is in numbers
How do you calculate the last index of an array?
length of the array - 1
What is a function in JavaScript?
A set of statements that performs a task
Describe the parts of a function definition.
function -> name (parameters) { code -> optional return }
Describe the parts of a function call.
nameOfFunction(arguments);
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function call doesn’t include a code block
What is the difference between a parameter and an argument?
A parameter is a placeholder which will eventually become an argument with a function call
Why are function parameters useful?
Allows functions to perform tasks without knowing the inputs ahead of time.
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we can use in our program. And prevents any more code in the function’s code block from being run.
Give 6 examples of comparison operators.
< > <= >= === !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
to check for certain conditions or to force certain parameters
Describe the syntax (structure) of an if statement.
if (parameters) { return: what you want code to do; }
What are the three logical operators?
& || !==
How do you compare two different expressions in the same condition?
& ||
What is a method?
An object reference to a function
How is a method different from any other function?
object.
How do you remove the last element from an array?
.pop()
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(start index, how many, optional replace)
How do you append an element to an array?
.push()
How do you break a string up into an array?
.split()
Do string methods change the original string? How would you check if you weren’t sure?
No, and with console.log()
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 JSON?
JavaScript Object Notation, used for storing and transporting data
What are serialization and deserialization?
Serialization converts an object into a byte stream and Deserialization does the opposite.
Why are serialization and deserialization useful?
Serialization allows you to save an object in a file or database. Deserialization takes that saved object and recreates it somewhere else.
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify()
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse()
How do you store data in localStorage?
window.localStorage.setItem()
How do you retrieve data from localStorage?
window.local.Storage.getItem()
What data type can localStorage save in the browser?
string
When does the ‘beforeunload’ event fire on the window object?
before the page is refreshed or left
What is a method?
A function that is a property of an object.
How can you tell the difference between a method definition and a method call?
A method definition has a return statement
Describe method definition syntax (structure).
the object’s property (name for function) followed by function (anything) { random code; optional return;}
Describe method call syntax (structure).
The name of the object followed by it’s property in dot notation followed by it’s arguments. console.log(‘Doggo’, doggo);
How is a method different from any other function?
A method is associated with an object
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both data (as properties) and behavior (as methods)
What are the four “principles” of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is “abstraction”?
The process of generalizing details
What does API stand for?
Application Programming Interface
What is the purpose of an API?
To allow for two or more computers to communicate with each other.
What is this in JavaScript?
An implicit parameter of all JavaScript functions
What does it mean to say that this is an “implicit parameter”?
It’s baseline
When is the value of this determined in a function; call time or definition time?
call time
How can you tell what the value of this will be for a particular function or method definition?
You can’t
How can you tell what the value of this is for a particular function or method call?
Object to the left of the period
What kind of inheritance does the JavaScript programming language use?
Prototypal
What is a prototype in JavaScript?
Prototypes are the mechanism by which JavaScript objects inherit features from one another.
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?
They are objects?
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
In it’s prototype
What does the new operator do?
- Creates a new object
- It sets this new object’s internal, inaccessible, [[prototype]] (i.e. __proto__) property to be the constructor function’s external, accessible, prototype object (every function object automatically has a prototype property).
- It makes the this variable point to the newly created object.
- If no return statement, object gets returned
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
What does the instanceof operator do?
It tests whether the object is an instance of the specified type
What is a “callback” function?
Passing a function as an argument
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout()
How can you set up a function to be called repeatedly without using a loop?
setInterval()
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
What do setTimeout() and setInterval() return?
Interval id