The 10-second Guide to JSLint (Or, What’s the Difference Between ‘ == ‘ and ‘ === ‘?)


10-second guide to JSLint

No semicolons.

Use === instead of == .

No ++ or — .

Use /*global*/ to declare variables, like this: /*global foo, bar */ .

Use /*globals*/ to declare a bunch of variables at once. These are things you use but do not define. For example, if you use the window object in your program, put /*globals window */ at the top. (This is just like declaring a global variable in C.)

If you forget to declare a function that is not part of another function (that is, a function that does not have its own var ) then the function will be global! JSLint will complain about all such functions because it is impossible to tell which functions are meant to be global and which should have been declared locally. If you know that a function should be global, you can fix this problem by putting “/*global myFunctionName */” before it. This also applies to variables.

You cannot have multiple var s in the same scope. Put them all on one line with commas between them: “var x = 1, y = 2;”. You can have multiple vars if they are in different scopes

After a few years of writing JavaScript, I still have to look up the difference between == and ===. I mean, sure, there’s a difference, but is it really necessary? Why can’t we just have one way of comparing whether two things are equal?

JSLint exists to answer those questions. It was created by Douglas Crockford in 2002 to enforce his coding style on projects. It has since become arguably the most widely used code quality tool for JavaScript projects.

So what exactly is JSLint? Literally, JSLint is a function that takes source code as input and returns a description of any syntax problems found.

When I started learning JavaScript, I was confused about the difference between ‘ == ‘ and ‘ === ‘.

At first glance, it looks like they do the same thing. But they don’t. There’s a huge difference between the two, so it’s important to understand when to use each one.

‘ == ‘ will evaluate to true when the values of its operands are equal, after doing any necessary type conversions. If it needs to convert between numbers and strings, for example, it will convert the string to a number before comparing them.

‘ === ‘ on the other hand will not do any type conversion. If the values are not the same type (and not both null or undefined), then it will immediately return false without converting anything.

This is very important because sometimes you might want to check that two values are really equal without any type coercion.

What’s the difference between ‘==’ and ‘===’, or between ‘function()’ and ‘function’?

The short answer: Everything.

The longer answer: Everything in JavaScript is an object. Except if it is a string. Or a number. Or a boolean value … Well, you get the idea.

So when you try to compare two values with the double equals operator (==), JavaScript looks at the value of the right side, converts it to the type of the left side, and then compares them for equality. If you use triple equals (===), then no conversion takes place before comparison.

In addition to primitive types, JavaScript offers two built-in objects that can hold primitive values: String and Number. The typeof operator returns different results for these two objects than for the corresponding primitive types:

typeof “12”; // “string” typeof String(“12”); // “object” typeof 12; // “number” typeof Number(12); // “object”

In JavaScript, the way to check for equality is with a double-equals sign (==). It’s called a “double” because it checks for two things: the value of the objects and their types.

In JavaScript, there are several different data types. They are:

string (e.g., “hello”)

number (e.g., 3)

boolean (true or false)

function (a block of code that can be executed)

null (an empty value)

undefined (the absence of a value)

This is a quick introduction to JSLint, a program that checks your JavaScript code for potential bugs and errors. You can run it online at http://www.jslint.com/ or install it locally on your computer.

The Problem

JavaScript is poorly understood by most programmers. This is not entirely the fault of the programmer because JavaScript was originally intended to be a simple scripting language for amateurs and as such, did not require extensive training to use effectively. It was never intended to be used as broadly as it is today, but over time it has become one of the most popular programming languages in existence (measured in terms of the number of people who have written non-trivial programs in the language).

Because few people have had formal training in JavaScript, many common mistakes are made over and over again. These mistakes cause bugs and reduce reliability, security, and maintainability. JSLint is designed to find these mistakes early and automatically so that you can spend less time debugging and more time doing what you do best: writing code!

How Does It Work?

JSLint scans your code character by character looking for potential problems. For example, JSLint will alert you if you forget to include a semi-colon at

null means nothing. undefined means a variable has been declared but not assigned a value.

The typeof operator returns a string that tells the type of the operand.

The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if two values are not the same type === will simply return false. Ex: 0 == false, but 0 !== false

A triple equal (===) is strict in its comparison and won’t coerce any values to be compared. A double equal (==) will try to convert data types to be compared

The difference between using var, let and const is really about how you want your variable to behave. If we want to use a variable anywhere in our application and not just in one block then we would use var. If we want to limit the scope of our variables to be inside of one block then they should be let or const depending on if we want to change them later or not.


Leave a Reply

Your email address will not be published. Required fields are marked *