Javascript-Rocks

Topics we cover today :
How Javascript works – Call stack, Heap, Worker Threads or Web Api, Callback, Callback Queue
Asynchronous Programming with Javascript
Javascript Promise
Javascript in Advance


What is Javasript?
A single threaded non-blocking asynchronous concurrent runtime

Higher order function
Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.

Javascript runtime:
A single threaded non-blocking asynchronous concurrent runtime

What is single thread?
One thread ==One call stack == one thing at a time

What is non-blocking?

Concurrent?
Our apps are working concurrently right? But how?

Actual javascript runtime has heap and call stack. Now, What is heap?
What is call stack?

Call stack:
function meLast(){
throw Error("");
}
function meSecondLast(){
console.log("me second last");
meLast();
}

function meFirstOne(){
console.log("me first one");
meSecondLast();
}

meFirstOne();

Internal javascript runtime has stack, heap but we have other terms in the form of browser or node server.
like; Event loop, callback queue, web api and some other stuff.




Promise?
Lets get famillar with term Push and Pull system ie. Producer and Consumer

Pull System?
//Producer--Passive Producer
function getData(){
  return { firstName : "Steven", lastName : "Roare" };
};

//Consumer--Active Consumer
var receivedData = getData();
Consumer determines when it recieves data from producer

Push System?
//Passive consumer
function passiveConsumer(){
    console.log("Passive consumer is called");
}

//Producer-Active
setTimeout(passiveConsumer, 10000);
Producer determines when to send data to consumer

Promises are most common type of push system in javascript today.
Promise in Angular : $q, $http, $resource

Did you see problem with promise?
It is not cancellble
-It is executed only at a time
-Push system with one value

What is RxJS?
RxJS is a library for composing asynchronous and event-based programs by using observable sequences. RxJS introduces Observables, a new Push system for JavaScript. An Observable is a Producer of multiple values, "pushing" them to Observers (Consumers).

Lets learn future of reactive programming RxJS together.And grow in ourselves giving greater shape to our projects.


Comments