I am starting to learn about event object this week, and I can not wrap my head around it.
Please, excuse any typo as english is not my native language, and I will try to be clear.
What is exactly event object? when is it executed? why do we have it?
For example:
- when we use an anonymous function as in this example, the event object will not be renderPosts() function.
window.addEventListener(‘DOMContentLoaded’, () => renderPosts());
const renderPosts = async () => {
let uri = 'http://localhost:3000/posts?_sort=likes&_order=desc';
const res = await fetch(uri);
const container = document.querySelector(".blogs");
- when we do not use anonymous function as in this example, the event object will be renderPosts() function.
window.addEventListener(‘DOMContentLoaded’,renderPosts());
const renderPosts = async () => {
let uri = 'http://localhost:3000/posts?_sort=likes&_order=desc';
const res = await fetch(uri);
const container = document.querySelector(".blogs");
I do not see the difference and not really understand it. I have been searching about event object, but still confused.
Appreciate any explanation.