mode 5 JS III Flashcards

1
Q

What is a scope?

A
  • the memory space where a variable exists

- it has NOTHING to do with permissions, nothing to do with access levels.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What scopes does JavaScript support?

A
  • global scope: the variables/entities can be accessed by everything
  • function scope: only accessible withing the specific function it is declared
  • block scope: only accessible within the block it is declared
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Hww do I declare a variable in JS?

A
  • var only enforce the “global” and “function” scopes
  • let enforces all 3 scopes
  • const same as “let” BUT it makes the value immutable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Scope access

A

I CAN access my global variable from the global scope,

I CAN access my global variable from the function scope,
I CAN access my function variable from the function scope,

I CAN access my global variable from the block scope,
I CAN access my function variable from the block scope,
I CAN access my block variable from the block scope,
I CAN access randomVar from the block scope

I CAN access my block variable from the function scope, if the block variable was declared using "var"
    // block scope only functions appropriately when we use "let" to declare variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Hoisting?

A

Essentially, JS is a two pass translator. On the first pass through of a file, JS will find all global declarations and create those variables/functions. On the second pass through, JS will perform your program’s logic (like assignment, for-loops, method calls, etc).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do we work with VARIABLES WITH THE SAME NAME (but different scopes)

A
  • variables in a higherscope will be shadowed, meaning that they are more difficult to access.
  • using the variable name will access the “most immediate” scope’s version of the variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Using VARIABLES WITH SAME NAME AND THE SAME SCOPE

A

there is a window object inside of javascript’s “global scope”. Functions will be created inside of
this window object, using their names as their variableNames in the window object. SO, when you
create a second function with the same name, you’re essentially just reassigning the window
object’s variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DOES OVERLOADING EXIST IN JS?

A

no, overloading doesn’t exist in JS like you’d expect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an anonymous function?

A

ANONYMOUS FUNCTION: a function without a name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a callback function?

A

CALLBACK FUNCTION
-it’s a function that is passed as an argument to another function to be run at a later point in time.

Basically, using callback functions are used to chain functions and control the order in which they are called
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

SELF-INVOKING FUNCTIONS

What is an IIFE?

A

It is similar to initializer block
-Immediately Invoked Function Expression (aka Self-invoking function)

An IIFE is a function that calls itself.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a NESTED FUNCTION

A

A function inside another function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is CLOSURE in JS?

A
  • Closure are a way to create encapsulation in JS.

- A closure is a self invoking anonymous function that returns an inner function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Arrow Notation?

A

ARROW NOTATION (function shorthand notation)

(a,b) => a+b;  //this will return a+b immediately (automatic/implicit return value)
OR
(a,b) => {a+b; console.log(a+b);} //no implicit return value
OR
a => {console.log(a)}  //no implict return value
OR
() => {console.log("stuff")} //no implicit return value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the DOM?

A
  • Document Object Model

- The DOM is a virtual representation of the HTML page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Accessing DOM

A

GET ELEMENT BY ID: let para = document.getElementById(“para2”);

GET ELEMENT BY CLASSNAME: let header = document.getElementsByClassName(“headers”)

GET ELEMENT BY TAGNAME: document.getElementByTagName(“”)

17
Q

Using Query Selectors

A

you can utilized a pattern similar to CSS selectors (tagname, “.”, or “#”)

let selection = document.querySelector(“#para2”);

// selection.innerText= “blahblahblah”;

// let selection2 = document.querySelector(".para");
let selection2 = document.querySelectorAll(".para");
18
Q

How do we CREATE ELEMENTS DYNAMICALLY in JS?

A
//step1: creating our new element
let newDiv = document.createElement("div");
//step2: populate our new element with attributes....and stuff
newDiv.id = "newestDiv";
newDiv.setAttribute("title", "new div, who dis?"); //either of these two methods work the same
//step3: create a text node, then append to our new div element
let divText = document.createTextNode("new text node information");
newDiv.appendChild(divText);
//step4: appending our new div element onto an existing element that is currently being displayed
let newSelection = document.querySelector("#para1");
newSelection.appendChild(newDiv);
19
Q

Types of Events in JS?

A

onsubmit, onchange, click, dblclick, mouseup, mousedown, mouseenter,
mouseleave, mouseout, mouseover, mousemove, and more

(mouseover includes children elements, mouseenter doesn't)
(same with mouseout and mouseleave respectively)

there is also:
keyup, keydown, keypress, cut, paste, change(statechange), submit, etc
20
Q

What is bubbling?

A

The process of events propagating to their parent elements to trigger even more events of the same type.

So if a click events fires, that click event will be pased to all parents, grandparents, etc to trigger more click event functionality.

21
Q

What is capturing?

A

The process of events propagating from parent to child; the opposite of bubbling