Javascript Language Characteristics Flashcards

1
Q

What is a closure and how is it created?

A

A closure is when a function remembers its lexical scope even when it is executed outside of its lexical scope.

The module pattern requires you to enclose an inner function with an outer function and return a reference to the inner function from inside of that larger function.

It is created when you call the inner function outside of its scope.

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

How long does a closure stay around?

A

As long as there is a reference to that inner function

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

When should you use a WHILE loop?

A

When you do not know ahead of time how many times you need to loop. For example, you do not know the length of the items in a collection.

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

Lexical Scope in Javascript

A

Can refer to a variable by name without getting access errors

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

Global Scope in Javascript

A

Outer most scope and can be accessed anywhere else in the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
var newSaga = function( ) {
   foil = aFoil ( )
}

What will the following code above do with the variable foil?

A

JS interpreter will automatically create a variable for foil in the global scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
var newSaga = function ( ) { 
  if ( checkSomething( ) )  {
    var foil = aFoil( )
  }
}

Does the code block between the curly braces after the If statement create a new scope?

A

No, it does not. Only the curly brackets after a function declaration creates a new scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
var newSaga = function( ) {
   var foil = aFoil ( )
}

What will the following code above do with the variable foil?

A

It will declare a variable called foil inside of the lexical scope for newSaga.

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

What is the difference between the loose equality ==

and strict equality ===

A

Strict Equality === compares the values and the types

Loose Equality == compares the values

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

What is the difference between the bracket notation and dot notation when used with Objects in JS?

A

Bracket notation allows you to use variables as properties.

Dot notation explicitly uses that name as a property in an object.

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

Synchronous

A

Statement executes one after the other, on a single, unbroken timeline

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

Asynchronous

A
  • Happens at an unknown or unpredictable time
  • Callbacks are the default JS technique to handle Async code BUT this could lead to the pyramid of Doom / callback hell! – a way to avoid callback hell is to use promises

see: https://classroom.udacity.com/courses/ud898/lessons/5972243496/concepts/60459332750923
- Events, Network, Threads are example of asychronous behavior in JS.

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

Promises

A

4 States:

  1. Resolved – completed task
  2. Rejected – error
  3. Settled – Fulfilled or rejected
  4. Pending – still waiting

Can only settle once

When to use promises?

  • working with data from AJAX requests
  • web workers (runs on separate threads Async)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a paradigm?

A

Design patterns used in programming:

  • Object Oriented
  • Functional
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Explain Event Bubbling

A

Events rise up like bubbles through the DOM tree. Bubbling allows us to listen for events on ancestor elements.

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

Explain the following: ‘In JavaScript, functions are first class citizens’

A

This means that functions can be stored in variables or passed in as arguments to other functions.

17
Q

Explain callback functions

A

Callback functions are called after a certain amount of time has passed.