9 & 10/10 Days Of Javascript

9 & 10/10 Days Of Javascript

Day 9

Today we'll be learnings some of the topics that we have missed in the past few days.

Anonymous Function: As the name suggests a function that doesn't have any name is called an anonymous function. Well, if it doesn't have any name then how does it get executed? Let us understand this with an example.

Consider the following code:

document.addEventListener("click", b)
function b(){
  alert("CLICKED")
}

Here, as we have previously seen we used a browser feature and passed two values; one of them being a function. Now let's use the anonymous function to write the same code:

document.addEventListener("click", function(){
  alert("You CLicked")
})

You see rather than first defining a function and then calling it we used an anonymous function to skip the middle man. However, the anonymous function won't work outside the designated scope since it doesn't have any name and we can't call or reference it elsewhere.

Arrow Function;

document.addEventListener("click", () =>{
  alert("You CLicked")
})

If you run the above code you might get the same alert as we got previously. Well, an arrow function does is it makes our code a lot cleaner and easy to read. Also, if you can fit your entire function in one single line of code then you won't even need curly brackets like so:

document.addEventListener("click", () => alert("You CLicked"))

Function Hoisting Javascript has a special feature called Function Hoisting. It lets us access the function no matter where they are declared, unlike variables.

cool()
function cool(){
  concole.log("This is cool.")
}



l
console.log(testFeature)
et testFeature = 100

If you run the above code the function would run with no errors however testFeature would definitely throw an error.

Day 10

For Day 10 we have finally put all the skills that we have learned over the past 9 days to practical use. We'll be building a To-Do using HTML5, CSS3 and JavaScript. Try building the web-application and pushing it onto the localhost. You can take a look at my final application to get some ideas. Click here to view it.

Did you find this article valuable?

Support Parikshit Hiwase by becoming a sponsor. Any amount is appreciated!