A Complete Overview of JavaScript Events - All You Need To Know

dcode
4 Jan 202115:11

Summary

TLDRIn this informative video, Dom introduces the fundamentals of JavaScript events, ideal for beginners and those seeking a refresher. He covers HTML inline events, the crucial 'addEventListener' function, the JavaScript event object for capturing event details, and the distinction between standard functions and arrow functions in event handling. With practical examples, Dom demonstrates how to respond to user interactions like clicks and provides insights on when to use each function type for clear and effective coding practices.

Takeaways

  • πŸ˜€ JavaScript events allow you to react to user interactions on a webpage, such as clicks or form submissions.
  • πŸ“Œ The script introduces four main topics for understanding JavaScript events: HTML inline events, the 'addEventListener' function, the JavaScript event object, and the difference between standard and arrow functions in event handling.
  • πŸ”— HTML inline events are the simplest form of event handling but can be limiting due to the lack of complexity they can manage within the HTML attributes.
  • πŸ”§ The 'addEventListener' method is a preferred approach for attaching events to elements because it keeps JavaScript separate from HTML, making the code cleaner and more manageable.
  • πŸ“š The JavaScript event object provides detailed information about the event that occurred, such as mouse coordinates and whether modifier keys were pressed during the event.
  • πŸ‘‰ Inline event handlers can quickly become messy and are not recommended for complex projects, where separating JavaScript from HTML is advisable.
  • πŸ› οΈ Functions like 'onClick' and 'onMouseOver' can be attached to elements to define actions that should occur when specific events are triggered.
  • πŸ”„ When using 'addEventListener', you can specify the event type and a function to be executed when the event occurs, promoting better organization of code.
  • 🎯 The 'this' keyword behaves differently in standard functions and arrow functions within event handlers, with the former referring to the element that triggered the event and the latter to the global object.
  • πŸ‘¨β€πŸ« The video script is aimed at beginners and those with some experience who want to review JavaScript events, emphasizing the importance of understanding the basics for effective web development.
  • πŸ” The script suggests that developers should research and understand the various types of events available in JavaScript to effectively use them in their projects.

Q & A

  • What are JavaScript events, and why are they important?

    -JavaScript events allow you to react to specific interactions or occurrences on a web page, such as clicks, form submissions, or mouse movements. They are important because they enable dynamic and interactive user experiences by triggering actions when certain events happen.

  • What is an inline HTML event in JavaScript, and when might you use it?

    -An inline HTML event in JavaScript is an event handler directly placed within the HTML element, such as `onclick="alert('Hello!')"`. It's typically used in beginner tutorials for its simplicity but is not recommended for complex projects due to its limitations in maintainability and functionality.

  • What is the `addEventListener` function in JavaScript, and why is it preferred over inline events?

    -The `addEventListener` function is used to attach an event handler to an element separately from the HTML markup. It is preferred over inline events because it keeps the HTML clean, allows multiple events to be attached to a single element, and provides more flexibility in handling events within the JavaScript code.

  • How does the `getElementById` function relate to event handling in JavaScript?

    -The `getElementById` function is used to select an HTML element by its ID, allowing you to reference that element in your JavaScript code. Once selected, you can attach event handlers, such as using `addEventListener`, to respond to user interactions with that element.

  • What is the JavaScript event object, and what information does it provide?

    -The JavaScript event object, often referred to as `e` or `event`, contains information about the event that just occurred, such as the type of event (e.g., click, mouseover), the position of the mouse, and whether modifier keys like Alt or Ctrl were pressed. This information can be used to make the event handling more dynamic and responsive to user actions.

  • Why might you use an external function for handling events in JavaScript?

    -Using an external function for handling events in JavaScript, rather than defining the function inline, helps keep the code organized and reusable. It allows you to separate the logic from the event attachment, making the code easier to maintain, debug, and extend.

  • What is the difference between a standard JavaScript function and an arrow function in the context of event handling?

    -The main difference between standard JavaScript functions and arrow functions in event handling is how they treat the `this` keyword. In standard functions, `this` refers to the element that triggered the event. In arrow functions, `this` is inherited from the surrounding context, often leading to it referring to the global window object instead of the element.

  • Why might the `this` keyword behave differently in arrow functions compared to standard functions?

    -In arrow functions, the `this` keyword does not bind to the element that triggered the event but instead inherits `this` from the surrounding lexical context. This can lead to unexpected behavior, especially in event handlers, where you might expect `this` to refer to the element the event is bound to.

  • How can you log the event object to the console in JavaScript, and why would you do this?

    -You can log the event object to the console using `console.log(e)` within the event handler function. This is useful for debugging and understanding the properties of the event, such as the mouse coordinates or whether modifier keys were pressed, allowing you to tailor your event handling logic accordingly.

  • What are some common use cases for the information provided by the event object in JavaScript?

    -Common use cases for the event object include determining the position of the mouse during a click event, checking if modifier keys (like Ctrl or Alt) were held down, and accessing the target element that triggered the event. This information can be used to create more responsive and interactive user interfaces.

Outlines

00:00

πŸ“š Introduction to JavaScript Events

This paragraph introduces the concept of JavaScript events, explaining their purpose and how they allow developers to respond to user interactions on a webpage. It sets the stage for the video by outlining the topics to be covered, including HTML inline events, the addEventListener function, the JavaScript event object, and the difference between standard functions and arrow functions in the context of event handling. The paragraph emphasizes the importance of events for beginners and experienced developers alike, aiming to provide a comprehensive understanding of how events work in JavaScript.

05:02

πŸ”— HTML Inline Events and Their Limitations

The second paragraph delves into the use of HTML inline events, demonstrating how they can be used to trigger JavaScript actions directly within HTML elements. It provides a practical example using a 'div' element with an 'onclick' event that displays an alert message. The paragraph also touches on the limitations of inline events, such as the inability to handle complex logic within the event attributes, and suggests that separating JavaScript code from HTML using external scripts or files is a better practice for maintainability and scalability.

10:03

🎯 The Advantages of addEventListener

This paragraph highlights the preferred method of handling events in JavaScript: the addEventListener function. It contrasts this approach with inline events, showing how addEventListener allows for more complex and modular code. The paragraph includes a step-by-step guide on how to use addEventListener, from selecting the HTML element to defining the event type and the function that will be executed upon the event's occurrence. It also discusses the benefits of externalizing event handling functions and the use of the event object to access details about the event.

15:04

πŸ“Œ Understanding the JavaScript Event Object

The fourth paragraph focuses on the JavaScript event object, which contains information about the event that has occurred. It clarifies the role of the event object in providing details such as mouse position and keyboard state during an event. The paragraph demonstrates how to access the event object by passing it as a parameter to the event handler function and then using it to log information to the console. It also explains the various properties available within the event object that can be useful for different scenarios, depending on the project requirements.

βš”οΈ Standard Functions vs. Arrow Functions in Event Handling

The final paragraph discusses the difference between standard JavaScript functions and arrow functions when used as event handlers. It provides examples of both function types within the addEventListener method and explains the significance of the 'this' keyword in each context. The paragraph points out that 'this' refers to the element being interacted with in standard functions, whereas in arrow functions, 'this' refers to the global object, which can lead to errors if not handled correctly. The video concludes by emphasizing the importance of choosing the right function type based on the specific needs of the event handling scenario.

Mindmap

Keywords

πŸ’‘JavaScript Events

JavaScript Events are actions or occurrences that happen in a web browser or web application, which can be responded to by JavaScript code. They are central to the video's theme as they allow for interactive web pages. For example, the script discusses how events like 'click' or 'mouseover' can trigger actions such as displaying a dropdown menu or validating a form.

πŸ’‘Inline HTML Events

Inline HTML Events are JavaScript event handlers written directly within the HTML code, using attributes like 'onclick'. The video describes them as the most basic form of JavaScript event handling, but also points out their limitations, such as lack of scalability and maintainability, as seen in the example where 'onclick' is used to display an alert message.

πŸ’‘addEventListener

The addEventListener method is a JavaScript function used to attach event handlers to elements. It's highlighted in the video as the preferred way to handle events because it separates JavaScript code from HTML, making the code cleaner and more manageable. The script demonstrates how to use addEventListener to react to a 'click' event on a div element.

πŸ’‘Event Object

The Event Object in JavaScript contains information about an event, such as the type of event, mouse coordinates, and whether modifier keys were pressed. The video explains that this object is crucial for understanding the context of an event and provides an example of logging the event object to the console to inspect its properties.

πŸ’‘Arrow Functions

Arrow Functions are a more concise syntax for writing functions in JavaScript, introduced in ES6. The video contrasts arrow functions with standard functions, particularly in the context of event handling. It notes that 'this' inside an arrow function refers to the global object (like 'window'), unlike in standard functions where 'this' refers to the element that triggered the event.

πŸ’‘Standard Functions

Standard Functions, also known as function declarations or function expressions, are a traditional way of defining functions in JavaScript. The video points out that within standard functions, the 'this' keyword refers to the element that the event handler is attached to, which is important for understanding the scope and context of 'this' in event-driven programming.

πŸ’‘Event Handling

Event Handling is the process of responding to user actions or browser events with JavaScript. The video's main theme revolves around this concept, showing how to set up event listeners and handle events like 'click' to trigger actions. Event handling is essential for creating interactive web pages.

πŸ’‘DOM Manipulation

DOM Manipulation refers to the process of changing the Document Object Model (DOM) of a webpage using JavaScript. In the context of the video, DOM manipulation is implied when discussing how to change the behavior of HTML elements in response to events, such as showing an alert or changing styles.

πŸ’‘Event Properties

Event Properties are the details contained within the Event Object that provide information about the event. The video script explains how to access these properties, such as 'clientX' and 'clientY' for mouse coordinates, and 'ctrlKey' to check if the control key was pressed during the event.

πŸ’‘Function Externalization

Function Externalization is the practice of defining functions separately from the event listener invocation. The video demonstrates this by showing how to define a function named 'handleBoxClick' and then reference it in the addEventListener call, which promotes better organization and reusability of code.

πŸ’‘This Keyword

The 'this' keyword in JavaScript refers to the context within which a function is executed. The video script uses the 'this' keyword to illustrate the difference in context between standard functions and arrow functions in event handlers, where 'this' can refer to the element or the global object, respectively.

Highlights

Introduction to JavaScript events for beginners and a recap for experienced developers.

Definition of JavaScript events as a way to react to actions on a webpage.

Explanation of the basic concept of event and action in JavaScript.

Overview of four main topics to be covered in the video: HTML inline events, addEventListener function, JavaScript event object, and the difference between standard and arrow functions in events.

Usage of HTML inline events such as 'onClick' for beginner tutorials.

Limitations of inline event handlers in terms of complexity and maintainability.

Introduction to the 'addEventListener' function as the preferred method for handling events.

Demonstration of adding event listeners to a div element with an 'id' of 'box'.

Explanation of how to use different JavaScript events like 'click' and 'mouseover'.

Advantages of separating JavaScript code from HTML for better organization and scalability.

Example of defining and using an external function with 'addEventListener'.

Introduction to the JavaScript event object 'e' and its role in providing information about the event.

Description of properties within the event object, such as mouse coordinates and key presses.

Difference between standard functions and arrow functions in the context of 'this' keyword usage in event handlers.

Implications of using 'this' in arrow functions versus standard functions and potential errors.

Recommendation to use standard functions when 'this' keyword is needed to refer to the element.

Conclusion summarizing the basics of JavaScript events and the importance of understanding them for web development.

Transcripts

play00:02

hey guys how you going

play00:03

my name is dom and today we're going to

play00:05

be taking a look at the basics of

play00:07

javascript events okay so today's video

play00:10

is going to be perfect for people who

play00:12

are just starting out to learn

play00:13

javascript or

play00:14

you've got a bit of experience under

play00:16

your belt and you just want to get a

play00:18

recap on how the events work

play00:20

okay so of course the first question

play00:22

here is going to be

play00:23

what exactly are javascript events well

play00:26

essentially they're going to allow you

play00:29

to react to when

play00:30

certain things happen on the page so for

play00:32

example

play00:33

when the user clicks on a button i want

play00:36

for example

play00:37

a drop down menu to show or another

play00:40

example might be

play00:41

when the user clicks on a submit form i

play00:44

want

play00:44

some sort of validation to happen so

play00:46

basically you have the event

play00:48

and then you have the action so in

play00:51

today's video

play00:52

we're going to cover four main topics

play00:55

around

play00:55

the events to of course gain an

play00:57

understanding of how they work

play00:59

so the first topic covered is going to

play01:01

be the usage of the very basic

play01:04

html inline events okay so these

play01:08

are things like your on click which

play01:10

you'll see on many beginner

play01:12

tutorials the second topic covered is

play01:15

going to be the usage of the add event

play01:17

listener function and this one here is

play01:19

arguably the most

play01:20

important the third topic is going to be

play01:23

the usage

play01:24

of the javascript event object and these

play01:27

ones right here

play01:28

are going to tell you information about

play01:31

the event which just occurred

play01:32

and the last topic is going to be the

play01:34

difference between a standard javascript

play01:37

function

play01:37

and an arrow function when it comes to

play01:39

the events so

play01:40

hope you guys enjoy and learn something

play01:42

from today's video

play01:44

let's get right into the first topic

play01:46

here the

play01:47

inline html events okay so

play01:50

starting off with the most basic form of

play01:52

a javascript event

play01:54

handler okay so right here i've got a

play01:56

fairly straightforward

play01:57

html file and we can see right down here

play02:01

i've got this div with an id of box and

play02:04

i've applied some

play02:05

fairly straightforward css styles to

play02:08

this

play02:08

box so now we can see in the browser

play02:11

it's going to look

play02:11

something like this so if i go back

play02:14

inside the text editor we can see

play02:17

inside the actual html for the box

play02:19

itself we can see

play02:21

it says on click alert hey

play02:24

decode so this right here is the most

play02:26

basic form

play02:27

of a javascript event and you'll find

play02:30

this style

play02:31

on many different beginner tutorials out

play02:33

there on the web

play02:34

now of course it's quite

play02:35

self-explanatory what this does

play02:38

when i click on the box i want this to

play02:41

say alert

play02:42

hey decode so now if i was to go inside

play02:45

the browser

play02:46

we can see upon clicking on the box we

play02:48

of course get hey

play02:50

decode right there and that is the most

play02:53

basic form like i said

play02:54

of a javascript event handler now

play02:58

of course if you're using a text editor

play03:00

like visual

play03:01

studio code if you go inside the actual

play03:03

div here

play03:04

and you specify for example o n or just

play03:07

on we can see there are many different

play03:10

events to choose from

play03:11

and of course when doing your own

play03:13

project you're going to be googling

play03:15

these things and finding out exactly

play03:17

what type of event you need to use for

play03:20

your own

play03:20

scenarios an example might be the on

play03:24

mouse over event and essentially it's

play03:26

going to allow you to react to when the

play03:28

user

play03:29

hovers their mouse over the actual div

play03:32

or the box in this case right here

play03:34

so for example i can just say alerts

play03:37

then i can say

play03:38

something like hover okay

play03:42

just like that so now if i was to save

play03:44

this we can

play03:45

we can see of course we actually have

play03:47

two event handlers right here

play03:49

the onmouseover and the on click and of

play03:51

course that is perfectly fine and valid

play03:54

to have

play03:55

so now saving this right here going

play03:57

inside the browser

play03:58

we can see if i was to hover over the

play04:00

actual box we get hover

play04:02

right there if i was to then click

play04:05

on the box we also get hey d code so

play04:09

right there we can see an example of

play04:10

adding the two events

play04:12

right there now what is the problem with

play04:14

this

play04:15

style of event handler well you can't

play04:18

actually do

play04:19

much inside these two

play04:22

inside these quotes okay so of course

play04:25

you can do quite a few things inside

play04:26

here but of course

play04:28

once your project gets more complex and

play04:30

you want to do

play04:31

many different things inside the event

play04:33

handler

play04:34

you're kind of restricted as to what you

play04:36

can do inside here

play04:38

and it can get very messy quite quickly

play04:40

so

play04:41

the better option is going to be to

play04:43

essentially put all of your javascript

play04:45

code

play04:46

inside its own separate you know section

play04:49

of the page or its own file

play04:51

and then do your event handling inside

play04:53

there instead

play04:54

it makes it much easier to work with and

play04:56

of course that brings us to

play04:58

the add event listener function okay so

play05:02

ad event listener is going to be the

play05:04

preferred way for you to add events to

play05:06

your javascript code

play05:07

and of course your web page so right

play05:09

here we can see we get a very similar

play05:11

example

play05:12

i've got the exact same div with an id

play05:15

of box but now

play05:16

i've opened up this script tag right

play05:18

here and i've specified some javascript

play05:21

code okay so essentially it's going to

play05:23

do the exact same thing

play05:24

and i can show you this right now so

play05:27

going inside the browser we can see

play05:29

upon clicking on the box we get right

play05:31

here hey

play05:32

d code so now looking at the actual code

play05:35

itself

play05:37

we can see in the javascript the first

play05:40

line of code here is simply grabbing

play05:42

the actual div from the html so right

play05:45

here i'm just saying

play05:46

a new constant or new variable

play05:50

called box div is equal to

play05:54

document.getelementbyid and i'm passing

play05:56

in box right here so

play05:57

for those of you who don't know

play05:59

essentially if i pass in box right here

play06:01

it's going to grab this div and now

play06:03

essentially this div

play06:05

refers to this box div right inside the

play06:08

javascript code

play06:09

so now i'm just simply saying box div

play06:12

dot add event listener and i'm passing

play06:15

through here

play06:16

the click event so similar to the

play06:19

previous example

play06:20

where we had the mouse over you can also

play06:23

pass in

play06:24

mouse over inside here and that is also

play06:27

going to work

play06:28

like i mentioned earlier there are many

play06:30

different javascript events to use so

play06:32

you're going to have to do your own

play06:33

searching and find out what you need for

play06:35

each different scenario

play06:37

but let's go back to the basic click

play06:39

event right here

play06:41

after this we're simply specifying a

play06:44

javascript

play06:45

function right inside here and i'm

play06:47

accepting

play06:48

the event object right there so we're

play06:51

going to get to this

play06:52

very shortly but for now we can simply

play06:54

ignore that

play06:55

and then going inside the actual

play06:57

function body itself

play06:58

i'm then saying alert hey d code so

play07:01

essentially

play07:02

we're moving the alert call from

play07:06

inside the html in the previous example

play07:08

to

play07:09

this function right inside here and this

play07:12

makes it

play07:13

a lot easier to work with and

play07:16

essentially

play07:16

you're going to have a much better time

play07:18

writing your javascript code

play07:20

inside the script tag or an external

play07:23

file

play07:24

compared to inside the html so of course

play07:27

we saw

play07:27

how that one works now what if i was to

play07:31

instead of specifying the function right

play07:34

here

play07:34

we can actually specify it externally so

play07:37

this right here is another example

play07:39

of what you might see so if i was to

play07:42

specify a function

play07:43

right inside here i can say function

play07:46

and call this function handle box

play07:50

click so essentially this function is

play07:53

going to do the job of handling

play07:55

the box click so now i can also accept

play07:58

the event object

play07:59

as we did earlier and then i can simply

play08:02

move

play08:02

the alert code inside here and then

play08:06

instead of having this function right

play08:08

here i can instead just say

play08:10

handle box click just like that and that

play08:13

is going to give us the exact same

play08:15

result it is simply just a different way

play08:17

of writing it

play08:18

and you might see this example or style

play08:21

also

play08:22

so if i was to save this we can see we

play08:25

get the

play08:26

exact same result we can click and we

play08:28

get hey

play08:29

decode so now we're going to move on to

play08:31

taking a look

play08:32

at the event object right here so let's

play08:35

look at that

play08:36

right now okay so moving on to the event

play08:39

object i'm referring to

play08:41

this e right here now i know this e

play08:44

confused me quite a bit

play08:46

when i first started learning javascript

play08:48

but it's actually very straightforward

play08:50

in what it actually does

play08:51

so essentially this e or the event

play08:54

object

play08:55

contains information about the event

play08:58

which has just

play08:59

occurred in the case of the click event

play09:02

you can find many different pieces of

play09:05

information

play09:06

about that click for example you can see

play09:09

if the user was holding down the alt

play09:12

or the control key when the click

play09:14

occurred or even

play09:15

the position of the mouse now to gain

play09:18

access to

play09:19

the event object you simply pass through

play09:21

a name

play09:22

for the event object right here inside

play09:25

the function now of course

play09:26

you can call this whatever you want for

play09:28

example

play09:29

it doesn't need to be e we can say ev

play09:33

or we can even say event right here

play09:35

realistically

play09:36

we could say absolutely anything like d

play09:39

code for example

play09:40

and that is also going to work but it is

play09:43

a nice convention

play09:44

to simply use e or ev as the name for

play09:48

the event

play09:49

object okay so that being said

play09:52

we can then reference or use the object

play09:54

inside the function

play09:56

by saying e just like this now

play09:59

right here i'm simply saying console.log

play10:02

and i'm passing through e

play10:04

so essentially this console.log is gonna

play10:07

tell me

play10:07

information about the actual object

play10:10

right there

play10:11

inside the javascript developer console

play10:14

so now if i was to save this right here

play10:16

and go

play10:17

inside the browser i can then using f12

play10:21

you can toggle the developer tools right

play10:23

inside here

play10:24

and you may need to switch to the

play10:26

console output right up here

play10:28

to gain access to of course the console

play10:30

so now

play10:32

if i was to click on the object we can

play10:34

see

play10:35

so on the div we can see right here we

play10:37

get the mouse

play10:38

event inside the console right here and

play10:41

notice how it says

play10:42

mouse events there are many different

play10:45

event

play10:46

objects in javascript because of course

play10:48

this one right here

play10:49

was a click event a click event relates

play10:52

to the mouse so of course we get the

play10:53

mouse event

play10:54

there is also the keyboard event for

play10:57

example

play10:58

so now going inside the actual object

play11:00

itself we can see

play11:01

there are many different properties

play11:03

related to

play11:04

the event which has just occurred for

play11:07

example

play11:07

we gain access to the client x and the

play11:10

client y

play11:11

and these are just the the mouse

play11:14

coordinates

play11:14

when the click occurred we can see we

play11:17

get 108

play11:18

and 80 right inside here if i was to

play11:20

click

play11:21

again this time in the top left corner

play11:24

we can see the client x and the client y

play11:27

are much lower at 10 and 10.

play11:31

we also gain access to things like the

play11:33

control key

play11:34

and the alt key which of course tell you

play11:37

if the alt or control key were pressed

play11:40

or held down when the click occurred for

play11:42

example we can see now

play11:44

the control key is set to false but if i

play11:46

was to hold the control key

play11:49

and click again we get right inside here

play11:52

control key

play11:52

sets a true so of course depending on

play11:55

your own

play11:56

scenario or use case you're gonna find

play12:00

these properties useful okay so of

play12:02

course

play12:03

it's gonna depend on your own project

play12:05

what you're doing

play12:06

you may not need to use any of these

play12:08

properties and that's perfectly fine but

play12:10

in many cases you may need to gain

play12:12

access to these different

play12:14

information regarding the event to of

play12:16

course do

play12:17

different things okay so let's let's

play12:19

move on now to

play12:20

the usage of the of the arrow functions

play12:24

in comparison to the standard javascript

play12:26

functions

play12:27

okay so moving on to the final part of

play12:30

today's video and that is going to be

play12:32

the difference between standard versus

play12:34

arrow functions

play12:35

when it comes to your event handlers

play12:37

okay so right here we can see

play12:39

i have two examples of the usage of the

play12:43

add event

play12:44

listener method okay so right here we

play12:46

can see

play12:47

the first example is very similar if not

play12:50

the same in fact it is the same

play12:52

as our previous examples we're simply

play12:55

saying function and then of course

play12:56

taking through the event object and then

play12:59

we're simply saying right down here

play13:01

console.log and i'm logging out the

play13:04

value

play13:05

of this keyword if you don't know what

play13:07

this keyword refers to

play13:09

that is perfectly fine this is still

play13:11

going to make sense

play13:13

in the second example this one right

play13:15

here is probably

play13:16

one of the more modern ways to write

play13:18

your javascript event

play13:20

handlers and this one uses an arrow

play13:22

function

play13:23

as we can see right here so these serve

play13:26

a very similar purpose

play13:28

and they do basically the exact same

play13:30

thing it's simply just

play13:32

a different way of writing out a

play13:34

javascript function

play13:35

this one is standard and this one is an

play13:37

arrow function

play13:39

now we can see i'm also logging out the

play13:42

value

play13:42

of the this keyword so now if i was to

play13:46

save this right here

play13:47

go inside the browser then click on the

play13:49

div we can see

play13:51

we get our two outputs right there

play13:54

as we can see in the case of the first

play13:56

example with the standard function

play13:59

this refers to or this keyword refers to

play14:02

the actual box itself so basically if i

play14:05

go back inside here

play14:07

in this case this refers to the exact

play14:10

same thing

play14:11

as box div right there and that is for

play14:15

standard functions

play14:16

when it comes to your arrow function

play14:18

this refers to

play14:20

the whole window global object itself

play14:24

so the reason why i pointed this out is

play14:26

because

play14:27

of course if you run into errors where

play14:30

you know certain things are defined or

play14:33

you know certain things aren't working

play14:35

just watch out for cases where you may

play14:38

be using an

play14:39

arrow function but then using this

play14:42

keyword always make sure if using this

play14:45

keyword right here

play14:46

you want to make sure you use the

play14:48

standard javascript function

play14:50

instead of the arrow functions right

play14:53

down here

play14:54

if you want to learn more about the

play14:55

arrow functions in javascript

play14:57

i've got a whole video dedicated to that

play14:59

so you can watch that too

play15:00

if you like and that is the basics of

play15:03

javascript

play15:04

events thanks for watching guys and i'll

play15:06

see you in the next

play15:09

video

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
JavaScriptEventsTutorialHTMLInline EventsEvent ListenerEvent ObjectArrow FunctionsDeveloper ToolsWeb Development