So this is an example of an onclick.
We've done this with the location href, and I've used used this to like put
a button and then change the browser to move to another thing.
But basically, this is an anchor tag Click Me, right?
And it says whenever this anchor tag is clicked,
which means if you click there, then run this JavaScript code.
And this is JavaScript code, it's an alert Hi, and return false.
Now see, it just runs it, two line of JavaScript.
JavaScript doesn't care about line ends or anything like that, or spacing.
And so you just indicate it together with semicolons to indicate
the end of each statement.
And so the return false, this is like a function call, basically.
And if you return false, what that does is suppresses the default behavior.
And the default behavior would be that you would click here and
it would follow this anchor tag.
But if this onclick runs it takes priority, it does the alert and
then it says, don't actually follow that link, okay?
And so you could return true, and it would follow the link.
You could run some JavaScript and
then after your JavaScript ran it would follow the link if that were true.
But when you click on this, it doesn't actually follow the link.
And it depends on this return value being false or true.
And so there's onchange and onclick, these are eventing.
And this is like in the earliest versions of JavaScript, there was an eventing
model that was put into various tags where you could run JavaScript.
because it's very much tied to the Document Object Model.
Including from a file, it's just like where you put the JavaScript
in the middle, except you just have a script and an end script.
And then you say source equals and then there is some code in that.
This code is not HTML, this code in this file is known to be JavaScript.
There's no <?php that has to happen at the beginning of it,
it just is JavaScript.
So up next we'll talk a little bit about how you detect errors when you're writing
JavaScript code.