JavaScript Flashcards
What is the purpose of variables?
to store data
How do you declare a variable?
you the keyword var and then the variable name
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letters, numbers, underscore, $
What does it mean to say that variable names are “case sensitive”?
upper case letters and lower case letters are different
What is the purpose of a string?
to hold a list of characters
What is the purpose of a number?
they are for math
What is the purpose of a boolean?
to return the value true or false
What does the = operator mean in JavaScript?
its an assignment operator
How do you update the value of a variable?
you put the variable name and = then the new value
What is the difference between null and undefined?
null means the variable has no value and undefined refers to a value that is empty or doesn’t exist
Why is it a good habit to include “labels” when you log values to the browser console?
to show what is being used
Give five examples of JavaScript primitives.
number, undefined, string, boolean, null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
When two or more strings are joined together to create one new string
What purpose(s) does the + plus operator serve in JavaScript?
It adds numbers together or concatenates strings
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 to the left variable
What are objects used for?
Grouping together a set of variables and functions to create a model of something you would recognize from the real world.
What are object properties?
A variable within an object.
Describe object literal notation.
declare the variable and name it then use curly brace and make property and value
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
Storing multiple pieces of data
Describe array literal notation.
Create an array and give it a name and then assign values inside of a bracket
How are arrays different from “plain” objects?
arrays are used for lists and arrays are used for the same data type
What number represents the first index of an array?
0
What is the length property of an array?
arrayname.length
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
A set of statements that perform a task
Describe the parts of a function definition.
Function keyword, parameters in parentheses, statement enclose in curly braces
Describe the parts of a function call.
function keyword and argument in parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call calls the function while the function definition determines what the function does
What is the difference between a parameter and an argument?
a parameter is used in a function definition, while an argument is used on a function call.
Why are function parameters useful?
It determines what is to be used as an argument for the function
What two effects does a return statement have on the behavior of a function?
it stops the function and returns whatever is after the return keyword
Why do we log things to the console?
So we can see what the output of something would be.
What is a method?
A method is a function which is a property of an object
How is a method different from any other function?
A method is an object property that has a function value, meanwhile a function is a block of code designed to perform a particular task.
How do you remove the last element from an array?
you use the .pop() method
How do you round a number down to the nearest integer?
you use the Math.floor method
How do you generate a random number?
you use the Math.random method
How do you delete an element from an array?
you use the .splice(start, deleteCount) method
How do you append an element to an array?
you use .push(element) method
How do you break a string up into an array?
you use the .split(separator, limit) method
Do string methods change the original string? How would you check if you weren’t sure?
No they are made into a new string. You can check using console.log method
Is the return value of a function or method useful in every situation?
No
Give 6 examples of comparison operators.
> , <, >=, <=, ===, !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
it allows us to make decision on our code.
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condtion) { conditional code block}
What are the three logical operators?
AND(&&), OR (||), NOT(!)
How do you compare two different expressions in the same condition?
using &&, ||
What is the purpose of a loop?
It allows you to repeat a process until a specific condition is met
What is the purpose of a condition expression in a loop?
the purpose is to stop a loop
What does “iteration” mean in the context of loops?
a repetition of the loop
When does the condition expression of a while loop get evaluated?
before the code block is executed
When does the initialization expression of a for loop get evaluated?
it gets evaluated first in the condition and it happens only once
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?
adds by 1
How do you iterate through the keys of an object?
you use the for in loop
What is JSON?
a standard text-based format for representing structured data based on JavaScript object syntax.
What is serialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.
What is deserialization
Deserialization is the reverse process: turning a stream of bytes into an object in memory.
Why are serialization and deserialization useful?
so you can turn your data into something that is more easily stored
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?
setItem
How do you retrieve data from localStorage?
getItem
What data type can localStorage save in the browser?
String
When does the ‘beforeunload’ event fire on the window object?
right when the window is going to close or be reloaded
What is a method?
A method is a function which is a property of an object.
How can you tell the difference between a method definition and a method call?
method definition includes parameters and it is inside of an object
Describe method definition syntax (structure).
its stored in an object and then the function name colon, then function keyword and parameters and function definition
Describe method call syntax (structure).
object then dot method name and argument
How is a method different from any other function?
Because it is stored in an object
What is the defining characteristic of Object-Oriented Programming?
Objects contain both data and behavior
What are the four “principles” of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
What is “abstraction”?
being able to work complex things in simple ways
What does API stand for?
Application programming interface
What is the purpose of an API?
Application programming interfaces, or APIs, simplify software development and innovation by enabling applications to exchange data and functionality easily and securely.
What is this in JavaScript?
It’s a keyword that refers to an object that is executing the current piece of code
What does it mean to say that this is an “implicit parameter”?
that it’s available in a functions code block even though it was never initialized
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?
It’s the object of the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototypal
What is a prototype in JavaScript?
an object with shared behavior or data that can be stored in one place but can be shared in all places
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?
If the string, array ,or number had a prototype
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
Each prototype object
What does the new operator do?
The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceof operator do?
It’s used to test whether the object is an instance of the specified type
What is AJAX?
A programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHTTPRequest
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
Load event
What is Array.prototype.filter useful for?
it’s useful for filtering