JavaScript Flashcards
What is the purpose of variables?
a vehicle to have permanence of data
How do you declare a variable?
var keyword
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letters, number $ and _
What does it mean to say that variable names are “case sensitive”?
uppercase =/= lowercase
What is the purpose of a string?
to hold text
What is the purpose of a number?
for math
What is the purpose of a boolean?
for conditionals, to make decisions
What does the = operator mean in JavaScript?
value is being assigned to
How do you update the value of a variable?
reassign new value (=)
What is the difference between null and undefined?
Null is an assigned value without value, undefined has never been assigned
Why is it a good habit to include “labels” when you log values to the browser console?
for context in the output
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
A number
What is string concatenation?
joining strings together
What purpose(s) does the + plus operator serve in JavaScript?
concatenation or addition
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What are objects used for?
To store multiple variables under one name
What are object properties?
individual piece of named data within an object
Describe object literal notation.
var object = {} with commas after each new variable
How do you remove a property from an object?
with the delete operator
What are the two ways to get or update the value of a property?
dot or square bracket notation
What is a function in JavaScript?
A repeatable set of actions with a specific name
Describe the parts of a function definition
Function keyword with the name of the function followed by () with optional parameters inside, curly braces with code inside and a return statement to give back a value
Describe the parts of a function call
Function name, (), with optional arguments inside the parentheses
When comparing them side by side, what are the differences between a function call and a function definition
A function call has just the name with the arguments inside the following parentheses. Whereas the definition has the word function followed by the functions name and parameters inside the parenthesis with a following code block containing a return
What is the difference between a parameter and an argument?
parameter is in the function definition. argument is the real data being passed to the function
Why are function parameters useful?
it allows you to have variance in the application of the function
Why do we log things to the console?
debugging, verification
What is a method?
A function in an object
How is a method different from any other function?
Function inside an object rather than by itself. function() vs obj.method()
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()
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, console log to check
Give 6 examples of comparison operators.
==, !=, ===, >, <, >=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
allows us to take decisions in our code
Is else required in order to use an if statement?
no
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
and, or
What is the purpose of a loop?
To be able to do things repeatedly
What is the purpose of a condition expression in a loop?
To create a point in which the loop will stop
What does “iteration” mean in the context of loops?
Each time the loop runs
When does the condition expression of a while loop get evaluated?
before each run
When does the initialization expression of a for loop get evaluated?
only once before it runs
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 run
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?
increases val of variable by 1
How do you iterate through the keys of an object?
for in loop
What are the four components of “the Cascade”.
Source order, specificity, !important, and inheritance
What does the term “source order” mean with respect to CSS?
the order that css rules are written in the stylesheet
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?
inheritance
List the three selector types in order of increasing specificity.
type, class, ID
Why is using !important considered bad practice?
Its high specificity makes it hard to overwrite
What event is fired when a user places their cursor in a form control?
focus
What event is fired when a user’s cursor leaves a form control?
blur
What event is fired as a user changes the value of a form control?
input
What event is fired when a user clicks the “submit” button within a <form>?
submit
What does the event.preventDefault() method do?
prevents the event from being submitted blank
What does submitting a form without event.preventDefault() do?
refreshes page with data in url
What property of a form element object contains all of the form’s controls.
elements
What property of a form control object gets and sets its value?
value
What is one risk of writing a lot of code without checking to see if it works so far?
you could be writing many bugs
What is an advantage of having your console open when writing a JavaScript program?
you can see a log after every line of code you write
What is JSON?
text-based data interchange format based on javascript object syntax
What are serialization and deserialization?
turning pieces of data into a string of data
Why are serialization and deserialization useful?
to be able to send data and make it easy to receive
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.parse method
How do you store data in localStorage?
setItem(key, value)
How do you retrieve data from localStorage?
getItem(key)
What data type can localStorage save in the browser?
String
When does the ‘beforeunload’ event fire on the window object?
before closing the tab
What is a method?
A function assigned to a property of an object
How can you tell the difference between a method definition and a method call?
Definition has a function keyword and a code block in assignment, call has a obj name with ()
Describe method definition syntax (structure).
Function name with : then function keyword and paramteters inside () and a code block
Describe method call syntax (structure).
object name and dot then method()
How is a method different from any other function?
it has dot notation
What is the defining characteristic of Object-Oriented Programming?
Objects can contain both data and behavior
What are the four “principles” of Object-Oriented Programming?
abstraction, inheritance, encapsulation, polymorphism
What is “abstraction”?
simplification for interaction with something complex
What does API stand for?
application programming interface
What is the purpose of an API?
allows apps to exchange data and functionality
What is this in JavaScript?
implicit parameter of all javascript functions, it gives the current object from where the function or method was called
What does it mean to say that this is an “implicit parameter”?
parameter that is given to all functions, and not listen in the parameter list
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 unless its called
How can you tell what the value of this is for a particular function or method call?
by seeing where it was called from
What kind of inheritance does the JavaScript programming language use?
Prototypal inheritance
What is a prototype in JavaScript?
an object with shared behavior or data that can be stored in one place and shared by all created instances
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?
because they have assigned prototypes with those methods
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
through its prototypal chain, one layer at a time
What does the new operator do?
Makes a new blank object with preset prototypes
What property of JavaScript functions can store shared behavior for instances created with new?
the prototype property
What does the instanceof operator do?
Tests if the prototype constructor is anywhere in the chain for the object
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()?
0ms
What do setTimeout() and setInterval() return?
an ID for the specific timer
What is AJAX?
building webpages using XMLHttpRequest to dynamically update
What does the AJAX acronym stand for?
Async 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?
the load event
What is the JavaScript Event Loop?
part of the runtime that pushes async requests to the call stack when the call stack is clear
What is different between “blocking” and “non-blocking” with respect to how code is executed?
no other code can run until the blocking code completes running