Javascript
/
Fundamentals
- 1 Fundamentals 11
-
Hello World S
-
Code structure S
-
Use strict S
-
Variables S
-
Data types S
-
Type conversions S
-
Maths S
-
Comparitions S
-
Conditional S
-
Loops S
-
Functions S
- 2 Testing 2
-
Mocha S
-
Nested describe S
- 3 Objects 4
-
Basics S
-
Reference S
-
Methods S
-
Constructor S
- 4 Types 5
-
Primitives S
-
Numbers S
-
Strings S
-
Arrays S
-
Json S
- 5 Classes 3
-
Constructor S
-
Binding S
-
Inheritance S
S
R
Q
Javascript Fundamentals Comparitions
A comparition result can be assign to a variable Use strict equality operator, less room for errors let a = 2 > 1 console.assert('01' != 1); // Incorrect console.assert('01' !== 1); // Correct
Boolean
All comparitions operators return a boolean value.
/**
* A comparition result can be assign to a variable
*/
let a = 2 > 1;
let b = 2 != 1;
console.log(a); // true
console.log(b); // true
Strict
The strict equality operator leaves less room for errors.
/**
* Javascript converts the values to numbers,
* when comparing different types
*
* Strict equality operator is recommended,
* no type conversion
*/
console.assert( '2' > 1 ); // pass Wrong
console.assert( '01' == 1 ); // pass Wrong
console.assert( '01' === 1 ); // failed Correct
➥ Questions