Skip to main content

Closures??? Anybody?

Well, say for example you have a button that turns on the outside lights of your home and the button in charge of doing that is on the street. The button works with no problems, but sometimes the neighborhood kids do pranks by turning them on and off. How do you think we can solve this problem?
I hear you, we can place the button inside the house and make clicking the button possible only to the residents of this place.
And what if the parents wanted to keep their children away from playing with lights?
They can place the button somewhere higher on the wall so that only THEY can access it.

Hope this was easy to understand :)

Comments

Popular posts from this blog

Stack vs. Queue

Stack is like a pile of  books placed on top of each other. We can add new books to the top and can remove them from only the top because stacks are LIFO which means last-in, first-out. Queues on the other hand are the opposite, which is FIFO meaning first-in, first-out. So adding an element to the queue will be the same but removing will happen to the first element not the last one. An example of a queue would be the wait line in front of any kind of service we see around us like the bus station or the shops,....etc.

Middlewares

Middlewares in Javascript are functions that come in the middle of the request-response cycle. They have access to both the request and the response object as well as the next middleware function to be executed; usually called next(). Popular examples on middleware include: body-parser, cors, session, cookie-seesion and cookie-parser.