Back
Written by Sandeep B on Sunday, October 6 2019

Javascript Journey

Hacking Nasa with Javascript
Share:

Hey there,

Alt text of image

I have been thinking about organising things i learned and still learning at a single place like this.

So instead of going to google and then stack overflow i can directly come right here.

Wow . Brilliant idea . Nobody would have never thought about this. Classic.

I know you may think like that. But wait. There is more. I bet you can find atleast one new thing from here.

Lets start with some very basic one.

What is a closure?

So baby pull me closure in the back seat of your ... nop not that.

A closure is basically an inner function that has access to the outer or enclosing function's variables.

details

So the canIGoToMars returns the inner function firstThingFirst. canIGoToMars function has a variable in its local scope called greeting. firstThingFirst function has access to the greeting variable . It console logs the greeting variable plus the name variable we pass into the canIGoToMars function.

An example of closure.

HTML

![details](https://i.ibb.co/st18K0x/carbon-2.png)

CSS

![details](https://i.ibb.co/4RTjLzd/carbon-3.png)

Javascript

![details](https://i.ibb.co/5c7ChVB/carbon-1.png)

{% codepen https://codepen.io/sandeepbalachandran/pen/NWWWOvd default-tab=js,result %}

###References MDN Web Docs [Dude Explaining Closure] (https://www.youtube.com/watch?v=71AtaJpJHw0)

Lets wrap up with a real complex javascript scenario only god can answer.

How to console a certain word without using its entire letters

Say here its 'banana'. We can use most likely

console.log(('b' + 'a' + + 'a' + 'a').toLowerCase());

Developers are still researching on this.

If we can go through their updates it would be

+'a' resolves to NaN ("Not a Number") because it coerces a string to a number, while the character a cannot be parsed as a number.

Thats it for now.

Edit this post on GitHub
Sandeep B

Sandeep B

Frontend engineer writing about Angular, JavaScript, and the occasional deep dive into whatever's currently breaking my build.

Subscribe to my
Newsletter

Subscribe to my newsletter to receive exclusive content, latest news and updates