Javascript Flashcards
What is the purpose of variables
variables hold a value of something
How do you declare a variable?
use the operator to declare a variable
How do you initialize ( assign a value to) a variable
you’d use the assignment operator
What characters are allowed in variable names?
letters dollar signs and underscore and numbers as long as it doesnt start with a number
What does it mean to say that variable names are “case sensitive”?
If its not case sensitive then two of the same words are different values
what is the purpose of a string?
Its a series of characters in a row. Data that is not code.
what is the purpose of a number?
calculations
What is the purpose of a boolean
to represent logic values and see whether its true or false
What does the = operator mean in JavaScript?
Its the assignment operator
How do you update the value of a variable?
set the old value on the left of the assignment operator and the new value on the right
What is the difference between null and undefined?
Null is a placeholder and undefined is javaScripts way of saying empty
Why is it good habit to include “labels” when you log values to the browser console?
It’ll give us a point of reference
Give five examples of JavaScript primitives
Strings, booleans, undefined, numbers, and null.
What data type is returned by an arithmetic operation?
A number.
What is string concatenation?
Joining two or more values together to form a new string.
What purpose(s) does the + operator serve in JavaScript?
To add numbers and to concatenate strings
What data type is returned by comparing two values
booleans
What does the += “plus-equals” operator do?
adds the value of the right operand to a variable and assigns the result to the variable
What are objects used for?
To create a model of something you would recognize in the real world. All stored together in one area
What are object properties?
They tell us about the object. Variables that live inside an object.
Describe object literal notation
The object the key value pairs inside curly braces
How do you remove a property from an object.
The delete operator
What are the two ways to get or update the value of a property?
Dot notation and bracket notation
What are arrays used for
it stores a list of values/groups of similar data
Describe array literal notation
variable then bracket index values end with commas brackets
how are arrays different from “plain” objects?
Arrays are listed in an order
what number represents the first index of an array
0
what is the length property of an array?
arr.length and gives the total amount of index in an array
how do you calculate the last index of an array?
Array.length - 1
What is a function in JavaScript?
A repeatable chunk of code with a specific purpose.
Describe the parts of a function definition
Function name parameter code block and function
Describe the parts of a function call.
The function name and the parentheses which is where arguments are passed through
When comparing them side-by side, what are the differences between a function call and a function definition?
definition has a code block.
What is the difference between a parameter and an argument?
parameters are placeholders for arguments that don’t ahve a known value.
Why are function parameters useful?
They are placeholder for arguments. If there were not parameters the behavior would always be the same. It gives us the ability to allow our behavior to act based on a certain set of values.
What two effects does a return statement have on the behavior of a function?
It causes the function to produce a value we can use in our program and prevents anymore code from running
why do we log things to the console.
To test debugging and inspect if our code works
what is a method?
A function which is a property of an object.
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 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() method
Do string methods change the original string? how would you check if you weren’t sure?
They do not, and console.log the original string and go to the MDN and look at the documentation of the return value.
Roughly how many string methods are there according to the MDN web docs?
A lot
Is the return value of a function or method useful in every situation?
Sometimes but not all the time
Roughly how many array methods are there according to the MDN web docs? a
A lot
What three-letter acronym should u always include in your Google search about a javascript method or CSS property?
MDN
give 6 examples of comparison operator
< > <= >= !=== ===
What data type do comparison expressions evaluate to?
booleans
what is the purpose of an if statement?
It evaluates if a condition is true then runs the code block
Is else required in order to use an if statement?
no
describe the syntax (structure) of an if statement
Function keyword function name parameter code block if statement followed by condition then curly brace return keyword
What are the three logical operators?
&& || ! logical and logical or logical not
How do you compare two different expressions in the same condition?
logical or operator
what is the purpose of a loop?
to perform repeated tasks based on a condition
What is the purpose of a condition expression in a loop.
to execute the statement if the expression evaluates to true and if its false it stops the loop
When does the initialization expression of a for loop get evaluated
once before the loop begins
What does “iteration” mean in the context of loops
every time the counter goes up by increment in the loop
When does the condition expression of a for loop get evaluated?
before each loop iteration
When does the final expression of a for loop get evaluated?
After the code block runs
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 one to its operand and returns a value
How do you iterate through the keys of objects?
for in loops
when does the condition of a while loop get evaluated.
before each pass through the loop
What are the four components of “the cascade”
specificity, inheritance, important source order
What does the term “source order” mean with respect to CSS?
The styling that is written last is the style that will show up on the html
How is it possible for the styles of an element to be applied to its children as well without an additional css ruleset?
it gets the css styling from the parent element
list three types of selectors in order of increasing specificity
type class and ID selectors
why is using !important consider bad practice
it makes debugging more difficult by breaking the natural cascading in your stylesheets
What event is fired when a user places their cursor in a form control?
focus
What even 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.preventDeafult() do?
Prevents the browser from automatically reloading with the forms values in the URL/prevents default behavior of the form
What does submitting a form without event.preventDefault() do?
automatically loads the form values
What property of a form element object contains all of the form’s controls.
The element
What property of a form control object gets and sets its value?
the value property
What is one risk of writing a lot of code without checking to see if it works so far?
You dont know if you ran into errors halfway through writing
What is an advantage of ahaving your console open when writing a javascript program?
To test your code to make sure its working
What is JSON?
A format we can represent data in most commonly used to send data across a network. Syntax is taht of a javascript object. it stands for javascript object notation
What are serialization and deserialization?
Serialization is the process of turning an object in memory into a stream of bytes so you can store it or send it over a network. Deserialization is the opposite where you turn the stream of bytes into an object in memory.
Why are serialization and deserialization useful?
You can send objects over a network and it can be parsed by the receiver
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 local storage?
setItem();
How do you retrieve data from local Storage?
getItem();
What data type can local Storage save in the browser?
string data
When does the ‘beforeunload’ event fire on the window object?
When the document and its resources are about to be unloaded.
What is a method?
A function definition which is stored in a property of an object.
How can you tell the difference between a method definition and a method call?
It shows all the code necessary to run that function. Curly brace, keyword function()
Describe method definition syntax(structure)
Method name with an anonymous function and the opening curly brace for the method code block and code to be run.
describe method call syntax(structure)
Method call has the method of the object being called with parentheses
How is a method different from any other function?
Its used on objects that include other methods and general data. Methods can use all the other tools inside the 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 and polymorphism
What is “abstraction”?
Being able to work with possibly complex things in simple ways.
What does API stand for?
Application programming interface
What is the purpose of an API?
To give programmers a way to interact with a system in a simplified, consistent fashion: aka, abstraction
What is this JavaScript?
An implicit parameter that is.
What does it mean to say that this is an “implicit parameter”?
Its available in a function code block event however it was never included in the functions parameters
What is the value of this determined in a function; call time or definition time?
Call time
Given the above character object, what is the result of the following code snippet? why? character.greet();
a function returning its a me mario
How can you tell what the value of this will be for a particular function or method definition
You can’t cause its not defined
How can you tell what the value of this is for a particular function or method call.
If its to the left of the dot and if there is no object then its the window global object.
WHat kind of inheritance does the javaScript programming language use?
prototypal inheritance
What is a prototype in JavaScript
a Javascript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects
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
Its placed in a prototype object and then the objects will delegate to that object when they aren’t able to perform the required tasks themselves
If an object does not have its own property or method by a given key, where does Javascript look for it?
within the __proto__ object
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceOf operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.
What is a “callback” function?
A function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of a routine or action
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?
timeoutID
What is a client?
A piece of computer hardware or software that accesses a service made by a server.
What is a server?
a piece of computer hardware or software that provides functionality for other programs or devices called clients
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?
An HTTP method the request target and the http version
what three things are on the start-line of an HTTP response message?
protocol version status code and status text
What are HTTP headers?
a case sensitive string followed by a colon and a value who’s structure depends upon the header and additional information
Where would you go if you wanted to learn more about a specific HTTP header?
MDN
is a body required for a valid HTTP request or response message?
No
What is AJAX?
a technique for loading data into part of a page without having to refresh the entire page.
What does the AJAX acronym stand for?
asynchronous javascript and XML
Which object is built into the browser for making HTTP requests in javascript?
XMLHTTPrequests
What event is fired by XMLHTTPRequest objects when they are finished loading the data from the server?
load event
AnXMLHttpRequestobject has anaddEventListener()method just like DOM elements. How is it possible that they both share this functionality?
because they are both objects?
They share the same prototype property