In this video, I want to talk for just a moment about linting tools. Now first, let me explain what a linting tool is. So Douglas Crockford, the person that created the default linting tool for JavaScript explained it when he was a programming language early on, there were a bunch of programming errors that were not caught by the compiler. So an accessory program was created called lint. And that was used to check the source files for certain problems. So a JavaScript linting tool checks your JavaScript for problems.
So basically, a linting tool is a syntax checker and verifier. Now, as I mentioned, J es lint is the default syntax checker for JavaScript. It's not the only one jass lint was developed by Douglas Crockford as I said, but I'm going to show you an another linting tool as well. So first j es lint, you can access yes lint by going to jslint.com. It provides a link where you can read the instructions of how to use it. And the main portion of the page is a place to paste your JavaScript code.
Now I'm going to select all the code from the event report that I created, and we'll check that code. So I simply copy it, jump back to J es lint, and then I paste it in. Now before I click the jesslyn button, I want to just set a few things. I'm going to assume that this is in a browser. These are some of the settings that I can choose for things I want to check. And then I'm also going to assume it's in development.
And then I clicked the button jslint now, I don't frequently use JS lint, it would be a good practice to do it. But I don't frequently use it because I guess you could say it's hurt my feelings too many times. It reports so many things about your JavaScript. And many of them are really, I think opinions as opposed to things that need to be changed. For. For example, let's look at some of the warnings that are in here.
One thing it doesn't like how I declare my variables, where I put a comma between variables and put them on separate lines, I think that's much easier to read. And therefore that's the reason I do that. Also with my function. It indicates that I should have a space between the function keyword and the first PRN and that's a good practice, I should probably start doing that it makes your code more readable and a differentiates between function call and a function definition because I looked Through this there are really none of the warnings that would cause my code to have problems. So those are the warnings that I've received for this code. Now, as I mentioned, jslint is not the only linter that's available for JavaScript.
J s hint is the one that I prefer. Jason can be found at Jason calm. Now before I paste my code into j s hint, I just want to provide a little information about why the makers of j s hint created Jess and it was actually a fork of j es lint. This is basically what they said. The tool by Doug jesslyn, the tool by Doug Crockford, the finds errors in your JavaScript code the project started because they thought that jslint was getting a bit too opinionated and they wanted it to become more community friendly. So j s hint is the The doesn't tyrannized your code is basically what they say.
So if I paste my code into j s hint, it gives me some metrics about my code. But I don't have any warnings. And it's not because it's not working. But I don't have any warnings. For example, I could add a bit of code that should produce a warning. And there it tells me one undefined variable x.
So that's something that I would need to crack because that can be a problem. Now, the value of j s hint and j es lint is it encourages you to improve your code. So jslint has a number of suggestions that according to Douglas Crockford will make your code more readable. And so I've used For that reason, I think his suggestions are very valuable. I love his book, JavaScript, the good parts, so I don't avoid it. But when I'm simply wanting to check my code for syntax issues, I use j s hint.
How you choose to move forward is really up to you. But I would encourage you to use one of these linting programs. Let's move on to the next topic.