Disadvantages of String.padStart()
- works only in modern browsers and environments;
- don't care about negative
- works only on String primitives not a Number
> (-4+'').padStart(7,'0')
"00000-4"
> (400.302).padStart(9, '0')
Uncaught TypeError: 400.302.padStart is not a function at <anonymous>:1:11
(0005).padStart(3, '0')
Uncaught TypeError: 5.padStart is not a function at <anonymous>:1:8
Features:
- cares about negative numbers
- cares about length -- don't cut just pads
- works with Numbers
- v2 works in legacy trash cans even in MS IE 3.1 and Rhino
- have a short way (defaults)