JavaScript Flashcards
What is the purpose of variables?
to be able to store and reference data
How do you declare a variable?
use the keyword var with its name
How do you initialize (assign a value to) a variable?
use =
What characters are allowed in variable names?
anything but cannot start with a number or a be a keyword
What does it mean to say that variable names are “case sensitive”?
capital letters are not the same as lowercase letters
What is the purpose of a string?
to store words into javascript
What is the purpose of a number?
used for counting and arithmetic
What is the purpose of a boolean?
to state yes or no within javascript
What does the = operator mean in JavaScript?
assign to
How do you update the value of a variable?
use the assign to and value
What is the difference between null and undefined?
null is empty on purpose. Undefined is nothing is defined (usually accident)
Why is it a good habit to include “labels” when you log values to the browser console?
So console can be organized and easier to read
Give five examples of JavaScript primitives.
String, Number, Boolean, Null, Underfined
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
combining strings
What purpose(s) does the + plus operator serve in JavaScript?
add or concatenation
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
take the variable and update value
What are objects used for?
a box to keep related stuff together
What are object properties?
exclusive variables for an object
How do you remove a property from an object?
Use the delete operator (ex: delete person.firstName)
What are the two ways to get or update the value of a property?
dot notation or with brackets
What is a function in JavaScript?
group of actions that are repeatable
Describe the parts of a function definition.
keyword function, function name, ( ) with parameaters if there are any, { }, return
Describe the parts of a function call.
the function name with ( ) including paramethers inside, if any
When comparing them side-by-side, what are the differences between a function call and a function definition?
definition has keyword function and { }, calling does not
What is the difference between a parameter and an argument?
parameter are a placeholder until arguments are sent in
Why are function parameters useful?
allows us to change the value of the variables being sent through the function
What two effects does a return statement have on the behavior of a function?
return stops function from running and returns the value to the outside of the function
What are arrays used for?
store a list of values (strings, numbers, boolean, objects)
Describe array literal notation.
var = [ ] using brackets
How are arrays different from “plain” objects?
arrays use an index while objects use keywords to organize data
What number represents the first index of an array?
0
What is the length property of an array?
the number of elements in the array
How do you calculate the last index of an array?
array.length - 1
Why do we log things to the console?
to follow the the code and for other developers to read
What is a method?
a function that is a proporty of an object
How is a method different from any other function?
syntax; with a method you must provide which object its connected to
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 , replace? )
How do you append an element to an array?
splice( start_index , how_many , replace? )
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, try it out or read some documentation
Is the return value of a function or method useful in every situation?
It does not need to be utilized in every instance
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
=== , !== , > , < , <= , >=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of a loop?
check a condition, more than once
What is the purpose of a condition expression in a loop?
to make the code run or stop the code
What does “iteration” mean in the context of loops?
one cycle of the code block
When does the condition expression of a while loop get evaluated?
before the iteration
When does the initialization expression of a for loop get evaluated?
at the start of the loop
When does the condition expression of a for loop get evaluated?
before every 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?
increase counter by 1
How do you iterate through the keys of an object?
for..in loop
What is the purpose of an if statement?
evealuates a condition, if true it will run
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condition) { }
What are the three logical operators?
AND&& OR|| !NOT
How do you compare two different expressions in the same condition?
by comparing their result
What are the four components of “the Cascade”.
- Source Order 2. Inheritance 3. Specificity 4. Important
What does the term “source order” mean with respect to CSS?
the order that the css rules are writtin on a stylesheet
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?
with inheritance
List the three selector types in order of increasing specificity.
~
Why is using !important considered bad practice?
Since it is just a quick fix it is not a long term fix
What is the className property of element objects?
string containing value of the class attribute
How do you update the CSS class attribute of an element using JavaScript?
use the className
What is the textContent property of element objects?
reads any text as a string to add/delete/update
How do you update the text within an element using JavaScript?
assigning a value to textContent property (var ____ = __nod__.textContent)
Is the event parameter of an event listener callback always useful?
No, does not need to be utilized
Why is storing information about a program in variables better than only storing it in the DOM?
so we can store the data and reference it
Why do we log things to the console?
check data to conform assumptions
What is the purpose of events and event handling?
to handle something that happned on the we page
What do [ ] square brackets mean in function and method syntax documentation?
that they are optional
What method of element objects lets you set up a function to be called when a specific type of event occurs?
________.addEventListener
What is a callback function?
functions to be used in the future
What object is passed into an event listener callback when the event fires?
object about info about the event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
property that references the html element being use in the event
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
handleClick is a function definition. While handleClick( ) is calling the function and the return value will be the argument
What does the new operator do?
- Creates a blank, plain JavaScript object;
- Links (sets the constructor of) the newly created object to another object by setting the other object as its parent prototype;
- Passes the newly created object from Step 1 as the this context;
- Returns this if the function doesn’t return an object.
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceof operator do?
if an object is a prototype of a constructor fucntion
What kind of inheritance does the JavaScript programming language use?
prototype inheritance
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?
prototypes allow us to base those on others objects
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
in the Object prototype
What is ‘this’ in JavaScript?
pointing to Object it is inside
What does it mean to say that this is an “implicit parameter”?
avalible in function code block even though it was never defined or given as a parameter
When is the value of ‘this’ determined in a function; call time/definition time?
call time
How can you tell what the value of this will be for a particular function or method definition?
cannot tell until method/function is called
How can you tell what the value of this is for a particular function or method call?
what is to the left of the .
How can you tell what the value of this is for a particular function or method call?
function definition stored as a property of an object
How can you tell the difference between a method definition and a method call?
definition has the keyword fucntion anf the { }. call has the ( ) at the end
Describe method definition syntax (structure).
definition has the keyword function anf the { }
Describe method call syntax (structure).
call has the ( ) at the end
How is a method different from any other function?
it is stored within an object as a property
What is the defining characteristic of Object-Oriented Programming?
objects can contain data (as properties) and behavior (as methods)
What are the four “principles” of Object-Oriented Programming?
- Abstraction 2. Encapsulation 3. Iheritance 4. Polymorphism
What is “abstraction”?
turns a complex thing into something easy to use
What does API stand for?
applications programming interface
What is the purpose of an API?
give programmers a way to interact with the system in a simplified way
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 ?
submit
What does the event.preventDefault() method do?
prevent the page from reloading when form is submitted
What does submitting a form without event.preventDefault() do?
Reload page
What property of a form element object contains all of the form’s controls.
_____.elements.___
What property of form a control object gets and sets its value?
.value
What is a “callback” function?
a function passes into another 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?
a unique ID that can be passed through clearInterval( ) to stop
What is AJAX?
a group of technologies that offer asynchronous functionality
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
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They share the event.target prototype
What is a client?
initiate request from server
What is a server?
provides a service (returns a response to client)
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What three things are on the start-line of an HTTP request message?
- HTTP Method 2. Request Target (url) 3. HTTP Version (usually 1.1)
What three things are on the start-line of an HTTP response message?
- HTTP Version (1.1) 2. Status Code 3. Status Text (description of code)
What are HTTP headers?
Specify the request /describe the body included in the message
Is a body required for a valid HTTP request or response message?
body is optional