Javascript
Well i was asked some questions related to javascript during an interview of Ola and was not able to answer that so i am writing this to help anyone who is going or lets say searching for an intern well i didn’t find one yet lol.
Event loop is something is which is constantly looking up at the call stack whether is there any callbacks in the callback queue it will push the first callback from the callback queue into the call stack for execution.
Callback queue — — → contains callback list who are waiting for the execution once the call stack is empty and hence,These tasks are added to the queue by Web APIs after they have completed their operation.
Web APIs are provided by the browser (or the Node.js runtime) and allow you to perform tasks that are outside the scope of the JavaScript language itself, such as making network requests, setting timers, or handling DOM events.
synchronous and asynchronous nature of javascript is the best part of it which makes the thing very easy for building web apps
In a layman terms async nature of javascript can be considered as deligate the task to someone you continuing with other task and conming back to it once the callback is called lol. I really hope you understand this.
classes is the coolest stuff i have seen in javascript it just lets you add functions and properties to any variable you have created according to the class
here we can see that according to the class we implemented the feature into the variable this the magic of classes.
Other than that javascript provides its own class such as the date class
const d = new date() — — → syntax of using classes (this is class provided by javascript itself)
so this class now exposes a bunch of functions with you
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date consider this to know about the functions being exposed by the date class for you
static methods
class rectangle {
constructor(width,height,color){
this.width = width;
this.height = height;
this.color = color;
}
static who(){
return “this is a rectamgle”
}
area(){
Get Akshat’s stories in your inbox
Join Medium for free to get updates from this writer.
return this.width* this.height;
}
}
// static method is somethinng that is called on the class itself not required to called on an a object
let rect1 = new rectangle(10,20,”red”);;
console.log(rect1.who())// this will give an error because who is a static method and we are trying to call it on an object
console.log(rectangle.who())// this will work because we are calling the static method on the class itself
console.log(rect1.area())// this will work because area is not a static method and we are calling it on an object
this is for better under-satanding
Inheritance in js allows you to inherit common properties from all the classes into another parent class which enables the childeren to call out the parent class for it to take the input for example
Now we can define a commom shape class which will be considerd as parent class and then henceforth called out
the syntax for it could be.
The shape class is now the parent class and now we can call color easily in the children class.
Now the given the code here in the ss shows a major problem of hoisting now whats hoisting — → hoisting in javascript is something related to delceleration of a function before calling it assume you are making a call without phone but the function of phone of phone should be defined first to use that phone to make a call, hence over here the shape function should be called first before extending any children class to parent class, ooh cool i have one more example of it it can be having childeren without parents lol. but yeah this is basic hoisting in js.
Now let me start with some difficult bits according to me about the promise class so basically promise is also a class used to perform some async task lets say reading a file setting a timeout….etc
So as of now we know that setTimeout is a async task and it can be called using a callback function this was how the things were being managed back in 2014 but from 2015 some good genius folks wrote the promise class which may have the then() function inside it catch() function inside it and what not.
So now the major bit of writing a promisified version of a readfile
now this looks big but yes this is syntactical sugur. makes easier to understand the code instead of writing basic stuff .then() shows that when ever the task is done pls callback a anaother function .catch() shows if err comes pls call another function and these then and catch is a function installed in the promise class itself
Would love to discuss more on my future vlogs………goodnight everyone.





