When to use e VS when to use Event


        const item = e.target;

       

        if(item.classList[0] === "trash-btn"){//if true

            const todo = item.parentElement;//const todo = TodoDiv

            todo.classList.add("fall");//adds classlist

            todo.addEventListener('transitionend', function(){//listens for end of transition

                todo.remove(); //DELETE TODO/

            })

        }

        

        if(item.classList[0] === "complete-btn"){//if true

            const todo = item.parentElement;//const todo = TodoDiv

            todo.classList.toggle('completed');//check Mark

        }

    }

    

    function addTodo(event){

        

        event.preventDefault() ///PREVENT from submitting/Because form default is to submit

Could someone Exmaplin when to use e Vs when to use event

Those are your function parameters, and there’s no specification on how you called it.

You could have called it whatever, it doesn’t really matter.
What it matters is that the Web API will always pass an Event object as arguments to that function… so you always know it’s an Event.

That’s why many people will call the param e (short for event), but you could have used any other name you like, it won’t change the outcome.

function foo(bar) {
  console.log(bar.type)
}

document.addEventListener("click", foo)

Will print in the console click every time I click in the document…
It’s just a very poor naming choice. :slight_smile:

Hope it helps.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.