Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
120 Cards in this Set
- Front
- Back
What can it do on web pages? |
Dynamically create, delete, modify the DOM structure of the HTML elements. - Change styling of the HTML elements. - Handleasyncrequestcallsandresponsemechanisms. |
|
where to put JS in HTML?
|
last elemnt of body they actually block parallel downloads |
|
Where are input and output functions in JavaScript? |
none |
|
is JS case sensetive ? |
yes |
|
how to declare JS variables? |
using var |
|
how to find var type |
using typeof |
|
declare strings |
var firstName = new String('JavaScript'); OR var firstName = 'JavaScript'; |
|
how to get value of a var? |
valueof() |
|
which stands for false values? |
0, -0, null, '', undefined, NaN, false : all evaluate to false; |
|
boolian var decl |
var myVar = new Boolean(true); or var myVar = new Boolean(); |
|
4 types of data types |
obj numbr string boolean |
|
function of try block |
The try statement lets you test a block of code for errors |
|
funxn of catch block |
The catch statement lets you handle the error. |
|
funxn of finally block |
The finally statement lets you execute code, after try and catch, regardless of the result. |
|
funxn of throws keyword |
The throw statement lets you create custom errors. |
|
2 ways of creating an object |
var obj = new Object(); //or var obj = {}; |
|
show an example which illustrates that JS objects can have multiple properties and is recursive |
var obj = { name: "Carrot", details: { color: "orange", size: 12 } }; |
|
use of Object.keys() |
to get an array of all the keys of obj |
|
2 ways of declaring an array |
var arr = new Array(); //or var arr = []; arr[0] = 'First'; arr[1] = 'Second'; arr[2] = 50; var arr2 = ['First', 'Second', 50]; //or |
|
how can you show array.length isn't necessarily the number of items in the array? |
console.log(arr2.length); //array.length isn't necessarily the number of items in the array. var a = ["dog", "cat", "hen"]; |
|
function of an array toString() method |
The toString() method converts an array into a String and returns the result. Note: The returned string will separate the elements in the array with commas. |
|
example of an array toString() method |
Convert an array to a string: var fruits = ["Banana", "Orange", "Apple", "Mango"]; The result of fruits will be: Banana,Orange,Apple,Mango |
|
concat(item[, itemN]) use? |
Returns a new array with the items added on to it. No change to original array. |
|
join() method use |
The join() method joins the elements of an array into a string, and returns the string. The elements will be separated by a specified separator. The default separator is comma (,). |
|
join method example |
Example Try using a different separator: var fruits = ["Banana", "Orange", "Apple", "Mango"]; The result of energy will be: Banana and Orange and Apple and Mango |
|
pop() method of an array |
Removes and returns the last item. Original array is modified. |
|
push() method of an array |
Adds one or more items to the end. Original array is modified. |
|
reverse() method of an array |
reverses array and modifies it |
|
shift() |
Removes and returns the first item. Original array is modified. |
|
slice(start, end) |
Returns a sub-array. No change to original array. |
|
sort([cmpfn]) |
Sorts items and takes an optional comparison function. Original array is modified. |
|
splice(start, delcount[, itemN]) |
Modifies an array by deleting a section and replacing it with more items. Original array is modified |
|
unshift([item]) |
Prepends items to the start of the array. Original array is modified. |
|
indexOf(item [, start]) |
Returns the first occurrence index of item in the array or -1 if not found. Optional start value. |
|
full form of JSON |
JavaScript Object Notation |
|
rules for JSON |
-Keys must be strings. |
|
simple example for JSON |
//multiple properties and recursive var obj = { "name": "Carrot", "details": { "color": "orange", "size": 12 } }; |
|
JSON objects must be _________________ |
JSON object should be serializable i.e. convertible to a string and vice-versa. |
|
NativeJSONParser[IE8+] |
var str = '{"name":"JavaScript","dob":1995,"author":"Brendan Eich","company":"Netscape"}'; //String to JSON object var obj = JSON.parse(str); console.log(obj.author); //prints Brendan Eich //JSON object to string var s = JSON.stringify(obj); |
|
how many return types do JS functions have ? |
JavaScript functions do not have return type. · JavaScript functions can return multiple data type values. |
|
basic syntax of a function |
function a(){// do some work and/or return }; |
|
example of JSON objects having funxns as properties |
|
|
how to check if a property is a funxn |
using typeof() |
|
Difference between two ways of declaring functions |
|
|
Can arguments can be accessed inside function even without specifying parameters |
|
|
what is the scope of variables within a function? |
they (those variables that are declared inside a fnxn) can only be accessed within the funxn, not outside |
|
what are global variables? |
variables declard outside a fnxn |
|
what are global variables attached to or how can they be accessed? |
|
|
how to access a variable that is declared inside a function? |
|
|
who has more priority for the same name - glob vars or local vars? |
local |
|
what is hoisting ? |
|
|
what can override a variable declaration when hoisted? |
|
|
what is JS strict mode? |
Allows you to place a program, or a function, in a “strict” operating context. · Catches some common coding bloopers, throwing exceptions. · Throws error in unsafe actions like accessing global object without var. · Throws error while accessing deprecated functions. |
|
example of strict mode |
|
|
what are closures? |
|
|
BOM |
browser object model |
|
window object |
The window object is supported by all browsers. It represent the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object. Global functions are methods of the window object. Even the document object (of the HTML DOM) is a property of the window object |
|
Create a element and append it to a element: |
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_createelement4
var para = document.createElement("P"); //Create a element
to with id="myDIV" |
|
document.createTextNode(); |
http://www.w3schools.com/jsref/met_document_createtextnode.asp
Example Create a element with some text: var para = document.createElement("P"); // Create a element
|
|
document.forms; |
The forms collection returns a collection of all elements in the document. |
|
what does "document.getElementById("demo").innerHTML" do? |
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_innerhtml
The innerHTML property sets or returns the HTML content (inner HTML) of an element. |
|
document.getElementsByName(name) |
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_getelementsbyname_loop |
|
what does window represent ? |
an open browser in a window |
|
what is an iframe? |
it is a separate window inside a window - example the output frame of plunker |
|
how to create new elements in JS? |
createElement() |
|
window.location |
location,url, hostname, etc |
|
window.history - all 3 of them |
window.history.go() window.history.back() window.history.forward() |
|
what are timing functions ? like for example setTimeout() |
it executes a fnxn after a certain period of time |
|
clearTimeout() |
The clearTimeout() method clears a timer set with the setTimeout() method. The ID value returned by setTimeout() is used as the parameter for the clearTimeout() method. Note: To be able to use the clearTimeout() method, you must use a global variable when creating the timeout method: myVar = setTimeout("javascript function",milliseconds); Then, if the function has not already been executed, you will be able to stop the execution by calling the clearTimeout() method.
http://www.w3schools.com/jsref/met_win_cleartimeout.asp |
|
window.open() and window.close() |
opens and closes a new window |
|
window.innerheight() window.innerwidth() |
Get the window's height and width: (NOT including toolbars/scrollbars)
http://www.w3schools.com/jsref/prop_win_innerheight.asp |
|
full form of DOM |
document object model |
|
DOM nodes |
In the HTML DOM (Document Object Model), everything is a node: * The document itself is a document node* All HTML elements are element nodes * All HTML attributes are attribute nodes * Text inside HTML elements are text nodes * Comments are comment nodes |
|
which html elements allow you to refresh or reload the page? |
links / anchor tags and form submission events !!!! |
|
local scope vs global scope |
for example we have -
var a = ......
function d (){ //something }
this 'a' variable is declared globally and accessible everywhere throughout
however if we had --
function d {
var a = ...
// something more }
then a - will have a local scope only restricted to that function - it might return undefined when called from outside the function
|
|
what will be the output be? --
|
|
|
what will the output be ?
|
it will be the 2nd alert message since newCustomer is false |
|
"Page protocol is " + window.location.protocol; |
Page protocol is http: |
|
Example Display the href (URL) of the current page: "Page location is " + window.location.href; |
Page location is http://www.w3schools.com/js/js_window_location.asp |
|
"Page host is " + window.location.hostname; |
Page hostname is www.w3schools.com |
|
what does the map funxn do ?
|
the map funxn takes in another function and applies that function to member of the array, so basically u cn say it acts like an array loop |
|
|
a doubled array |
|
u have the following array of names - how can you use map method to print them out as array of full names ? ---
var modifiedNames = [ "Thomas Meeks",
|
var modifiedNames = passengers.map(
|
|
make an array of functions |
var puzzlers = [ |
|
var a=[1,2,3,4] console.log(a.shift()); what will be the output? |
1 |
|
what will be the output when buildTicket( parkRides, fastPassQueue, wantsRide ); is called? how to change the function to an IIFE?
|
To change it to an IIFE we need to put
|
|
returning functions inside a function -- do you need () after the return statement ?
Like - function a() {
if(...) { return function () {........}; // Do you need a () here ? } }
|
No
|
|
|
adventureSelector(3)(); |
|
What happens in this code ? --
var puzzlers = [ var applyAndEmpty = function(input, queue) { alert(applyAndEmpty(start, puzzlers)); |
the queue array is emptied as it also performs operations on the numbr "start" as declared inside it ( queue is an array of functions) |
|
what will be the output ?
|
4 |
|
how can we access local variables, whose scope is only restricted to inside funxns? |
by using closures |
|
what will be the output of result ?
|
40 |
|
output of result ?
|
122 |
|
explain the concept of load order |
the first diagram looks ok - however if ( see the 2nd diagram ) the local variable is initialized or declared before sub funxn 2 and called before sub funxn 2 , the program will fail - hence the importance of load order ;
|
|
for the following piece of code, how does javascript load it / see it ?
|
|
|
what will be the output of the following piece of code ?
|
answer is 7
the code below shows how javascrip loads the code
|
|
Name a component of javascript which never gets hoisted |
funxn expressions |
|
what will be the output?
|
ans is 12
|
|
what will be the output ?
|
ans - error
|
|
what will be the output when capacity status(60, 60) is called ( ignore my syntax in this qxn) ? |
error
|
|
how can you correct the following piece of info so that , there is no error ? |
|
|
what are the 2 ways of referencing an object property ? |
dot notation and using square brackets (obj["property1"]) |
|
what will be the output of the following ?
|
error if u are using dot notation, u cant use dot and " " |
|
for the following piece of code how can you print out the destinations using a for loop --
|
|
|
what will be the output when --
return( delete obj1.prop1) |
true |
|
what will be the output when --
return( delete obj1.prop2)
[Note: obj1 doesnt have a prop2 ] |
true |
|
example of deleting a funxn property |
delete object.property1; |
|
can you calculate the length of an object like in array.length ? |
no - object.length will return undefined |
|
how to loop thru an object ? give a simple example |
|
|
how to determine the number of fish in an aquarium object ? put this function inside the object itself. |
|
|
what is an object's parent called ? Name 6 or 7 methods that any object inherits from it's prototype |
object prototype
|
|
what is inheritance ? |
inheritance is the concept when objects or arrays inherit properties or methods inherit from parent variables |
|
from where/whom does array objects inherit its properties from ? |
the Array prototype |
|
from where/whom the string inherit from ? numbers inherit from ? funxns inherit from ? |
string prototype number prototype funxn prototype |
|
who is the mother or father of all prototypes ? |
object prototype |
|
how to create a prototype method ? what is it's use ? |
for example , u had 10 string sentence variables and u wanted to count the nmbr of a's in all of them - you can create a method for the String prototype and then make all the string sentence variables inherit from them , instead of creating separate funxns for each of them;
|
|
how to create objects using object.create() ? |
|
|
examples of using isPrototypeOf() |
|
|
what is a class ? |
a class wud be a collection of similar type of objects
|
|
x=4; y="4"; console.log(x.valueOf()); console.log(y.valueOf()); console.log(x.valueOf()==y.valueOf()); console.log(x.valueOf()===y.valueOf());
|
4 "4" true(type coercion takes place) false ( no type coercion takes place ) |