js number add zero before 1

js number add zero before

('0' + 11).slice(-2) // '11'
('0' + 4).slice(-2)  // '04'

Here is what the above code is Doing:
1. The first line is a function declaration. It takes in a date object and returns a string.
2. The second line is a variable declaration. It’s a string that contains the format of the date we want to return.
3. The third line is a variable declaration. It’s a string that contains the format of the time we want to return.
4. The fourth line is a variable declaration. It’s a string that contains the format of the date and time we want to return.
5. The fifth line is a variable declaration. It’s a string that contains the date in the format we want.
6. The sixth line is a variable declaration. It’s a string that contains the time in the format we want.
7. The seventh line is a variable declaration. It’s a string that contains the date and time in the format we want.
8. The eighth line is a return statement. It returns the date and time in the format we want.

Similar Posts