Lesson #6


In JavaScript, a string is a sequence of characters enclosed in single or double quotes. The choice of quoting style is up to the programmer, and either style has no special semantics over the other. There is no type for a single character in JavaScript - everything is always a string.

Remember, that in JSON, the only allowed quote character is the double quotes.

To avoid making a choice every time you're about to write a string, you should pick one style and stick with it. If your team is still making up your mind - pick single quotes, they are more common. In ES6, you'll have a third option to enclose strings - the `backtick` string.

You know there are two different equality comparison operators in JavaScript: the === and == operators, or the triple equals and double equals as they're called. You’ve seen both used but aren't sure which one to pick for your code. You'd like to know a sure fire way to decide over one or the other.

As it turns out, there is a straightforward way to decide which one to use. And the same logic works for inequality comparison operators !== and != as well.

Compare equal and of same type with ===

x === y The triple equals operator (===) returns true if both operands are of the same type and contain the same value. If comparing different types for equality, the result is false.

This definition of equality is enough for most use cases. When comparing the string "0" and the number 0 the result is false as expected.