Calling functions from events

Coding with JavaScript

🕑 This lesson will take about 15 minutes

In this lesson, you will learn how to call functions from an event or using an event listener. In the examples in the video, a function written in JavaScript code will be called when a button is clicked.

Example - calling a JS function from an event in HTML

Here is the sample HTML and JavaScript code using no arguments for a function:

Example - calling a JS function from an event and using parameters

Here is the sample HTML & JavaScript code using a parameter with a function:

Example - calling a JS function using an event listener

Here is the sample HTML & JavaScript code for calling a function using an event listener.

Next lesson: Variable scope