-4
var a = '1000';
var b = '200';         

console.log(a > b);=> false

why?

Indent
  • 4,675
  • 1
  • 19
  • 35

1 Answers1

2

Because you are comparing strings, not numbers.

It compares each character in the same position from the left. So '1' is lower than '2' in character set, it stops comparing and returns false.

console.log('1000' > '200')
// false
console.log(1000 > 200)
// true
zmag
  • 7,825
  • 12
  • 32
  • 42