Best way to get date on YYYYMMDD format
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
5
down vote
favorite
I'm looking for the best way to return a date on a YYYYMMDD
format : i.e. : 20180106
Here is how I do it :
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
alert(yyyymmdd);
Is it correct enough or can I achieve the same in a beter way ?
Thank you for your light.
javascript datetime
 |Â
show 1 more comment
up vote
5
down vote
favorite
I'm looking for the best way to return a date on a YYYYMMDD
format : i.e. : 20180106
Here is how I do it :
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
alert(yyyymmdd);
Is it correct enough or can I achieve the same in a beter way ?
Thank you for your light.
javascript datetime
2
By the way, we are already in 2018. You wrote20170106
. ;)
â Roland Illig
Jan 6 at 17:23
To avoid those magic constants, you could also doconst components = [d.getFullYear(), d.getMonth() + 1, d.getDay()]; const paddings = [4, 2, 2]; components.map((component, i) => component.toString().padStart(paddings[i], '0')).join('');
â le_m
Jan 6 at 21:31
See also stackoverflow.com/questions/3552461/â¦
â mkrieger1
Jan 6 at 21:38
What do the fifth and sixth lines do? I'm learning JavaScript and I get the left part is a Boolean check but you're using "and" with code that sets a variable?
â BruceWayne
Jan 7 at 0:16
1
@BruceWayne if the boolean check is true, the right side statement will get executed (which here sets the variable), otherwise; if the left condition fails, it'll not execute.
â hjpotter92
Jan 7 at 6:27
 |Â
show 1 more comment
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I'm looking for the best way to return a date on a YYYYMMDD
format : i.e. : 20180106
Here is how I do it :
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
alert(yyyymmdd);
Is it correct enough or can I achieve the same in a beter way ?
Thank you for your light.
javascript datetime
I'm looking for the best way to return a date on a YYYYMMDD
format : i.e. : 20180106
Here is how I do it :
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
alert(yyyymmdd);
Is it correct enough or can I achieve the same in a beter way ?
Thank you for your light.
javascript datetime
edited Jan 6 at 21:05
asked Jan 6 at 16:46
user157436
2
By the way, we are already in 2018. You wrote20170106
. ;)
â Roland Illig
Jan 6 at 17:23
To avoid those magic constants, you could also doconst components = [d.getFullYear(), d.getMonth() + 1, d.getDay()]; const paddings = [4, 2, 2]; components.map((component, i) => component.toString().padStart(paddings[i], '0')).join('');
â le_m
Jan 6 at 21:31
See also stackoverflow.com/questions/3552461/â¦
â mkrieger1
Jan 6 at 21:38
What do the fifth and sixth lines do? I'm learning JavaScript and I get the left part is a Boolean check but you're using "and" with code that sets a variable?
â BruceWayne
Jan 7 at 0:16
1
@BruceWayne if the boolean check is true, the right side statement will get executed (which here sets the variable), otherwise; if the left condition fails, it'll not execute.
â hjpotter92
Jan 7 at 6:27
 |Â
show 1 more comment
2
By the way, we are already in 2018. You wrote20170106
. ;)
â Roland Illig
Jan 6 at 17:23
To avoid those magic constants, you could also doconst components = [d.getFullYear(), d.getMonth() + 1, d.getDay()]; const paddings = [4, 2, 2]; components.map((component, i) => component.toString().padStart(paddings[i], '0')).join('');
â le_m
Jan 6 at 21:31
See also stackoverflow.com/questions/3552461/â¦
â mkrieger1
Jan 6 at 21:38
What do the fifth and sixth lines do? I'm learning JavaScript and I get the left part is a Boolean check but you're using "and" with code that sets a variable?
â BruceWayne
Jan 7 at 0:16
1
@BruceWayne if the boolean check is true, the right side statement will get executed (which here sets the variable), otherwise; if the left condition fails, it'll not execute.
â hjpotter92
Jan 7 at 6:27
2
2
By the way, we are already in 2018. You wrote
20170106
. ;)â Roland Illig
Jan 6 at 17:23
By the way, we are already in 2018. You wrote
20170106
. ;)â Roland Illig
Jan 6 at 17:23
To avoid those magic constants, you could also do
const components = [d.getFullYear(), d.getMonth() + 1, d.getDay()]; const paddings = [4, 2, 2]; components.map((component, i) => component.toString().padStart(paddings[i], '0')).join('');
â le_m
Jan 6 at 21:31
To avoid those magic constants, you could also do
const components = [d.getFullYear(), d.getMonth() + 1, d.getDay()]; const paddings = [4, 2, 2]; components.map((component, i) => component.toString().padStart(paddings[i], '0')).join('');
â le_m
Jan 6 at 21:31
See also stackoverflow.com/questions/3552461/â¦
â mkrieger1
Jan 6 at 21:38
See also stackoverflow.com/questions/3552461/â¦
â mkrieger1
Jan 6 at 21:38
What do the fifth and sixth lines do? I'm learning JavaScript and I get the left part is a Boolean check but you're using "and" with code that sets a variable?
â BruceWayne
Jan 7 at 0:16
What do the fifth and sixth lines do? I'm learning JavaScript and I get the left part is a Boolean check but you're using "and" with code that sets a variable?
â BruceWayne
Jan 7 at 0:16
1
1
@BruceWayne if the boolean check is true, the right side statement will get executed (which here sets the variable), otherwise; if the left condition fails, it'll not execute.
â hjpotter92
Jan 7 at 6:27
@BruceWayne if the boolean check is true, the right side statement will get executed (which here sets the variable), otherwise; if the left condition fails, it'll not execute.
â hjpotter92
Jan 7 at 6:27
 |Â
show 1 more comment
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
The code looks good and works well. Since it provides a useful bit of work, you should convert it into a function. Then you can copy that function to another program if you need so.
function yyyymmdd()
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
return yyyymmdd;
To make this code a little easier to read, you should rename x
to now
.
You could also omit the calls to toString()
, which makes the code a little shorter. Plus, you should introduce the variables mm
and dd
, so that you don't reassign to the d
and m
variables. This is a generally useful pattern, because when stepping through the code you can always look at the variable definition to see how it was computed. This is not possible for variables that change their value during execution.
The modified code looks like this:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
var mm = m < 10 ? '0' + m : m;
var dd = d < 10 ? '0' + d : d;
return '' + y + mm + dd;
Or, you could inline the last few lines:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
return '' + y + (m < 10 ? '0' : '') + m + (d < 10 ? '0' : '') + d;
That last variant is harder to read though, therefore I prefer the previous one.
Another possibility is to define a helper function that produces a two-digit string:
function yyyymmdd()
function twoDigit(n) return (n < 10 ? '0' : '') + n;
var now = new Date();
return '' + now.getFullYear() + twoDigit(now.getMonth() + 1) + twoDigit(now.getDate());
There is also padStart.m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
add a comment |Â
up vote
2
down vote
For getting the 0
padded date and month values, I generally follow this approach:
let d = ('0' + x.getDate()).substring(-2)
However, the Date
objects have a .toISOString
method, which returns the string in YYYY-MM-DDTHH:MM:SSZ
format, which you can split on T
and then replace -
(or vice-versa):
formatted_date = (new Date()).toISOString().replace(/-/g, '').split('T')[0]
// same as (new Date()).toISOString().split('T')[0].replace(/-/g, '')
1
Woops... This first chosen solution has just failed. A new Date() likeSun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives2018-01-06T23:26:00.445Z
resulting in20180106
instead of the expected20180107
â user157436
Jan 7 at 0:55
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function liketoLocalISOString
, which would be quite useful.
â Roland Illig
Jan 7 at 15:54
add a comment |Â
up vote
-3
down vote
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
The code looks good and works well. Since it provides a useful bit of work, you should convert it into a function. Then you can copy that function to another program if you need so.
function yyyymmdd()
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
return yyyymmdd;
To make this code a little easier to read, you should rename x
to now
.
You could also omit the calls to toString()
, which makes the code a little shorter. Plus, you should introduce the variables mm
and dd
, so that you don't reassign to the d
and m
variables. This is a generally useful pattern, because when stepping through the code you can always look at the variable definition to see how it was computed. This is not possible for variables that change their value during execution.
The modified code looks like this:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
var mm = m < 10 ? '0' + m : m;
var dd = d < 10 ? '0' + d : d;
return '' + y + mm + dd;
Or, you could inline the last few lines:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
return '' + y + (m < 10 ? '0' : '') + m + (d < 10 ? '0' : '') + d;
That last variant is harder to read though, therefore I prefer the previous one.
Another possibility is to define a helper function that produces a two-digit string:
function yyyymmdd()
function twoDigit(n) return (n < 10 ? '0' : '') + n;
var now = new Date();
return '' + now.getFullYear() + twoDigit(now.getMonth() + 1) + twoDigit(now.getDate());
There is also padStart.m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
add a comment |Â
up vote
3
down vote
accepted
The code looks good and works well. Since it provides a useful bit of work, you should convert it into a function. Then you can copy that function to another program if you need so.
function yyyymmdd()
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
return yyyymmdd;
To make this code a little easier to read, you should rename x
to now
.
You could also omit the calls to toString()
, which makes the code a little shorter. Plus, you should introduce the variables mm
and dd
, so that you don't reassign to the d
and m
variables. This is a generally useful pattern, because when stepping through the code you can always look at the variable definition to see how it was computed. This is not possible for variables that change their value during execution.
The modified code looks like this:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
var mm = m < 10 ? '0' + m : m;
var dd = d < 10 ? '0' + d : d;
return '' + y + mm + dd;
Or, you could inline the last few lines:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
return '' + y + (m < 10 ? '0' : '') + m + (d < 10 ? '0' : '') + d;
That last variant is harder to read though, therefore I prefer the previous one.
Another possibility is to define a helper function that produces a two-digit string:
function yyyymmdd()
function twoDigit(n) return (n < 10 ? '0' : '') + n;
var now = new Date();
return '' + now.getFullYear() + twoDigit(now.getMonth() + 1) + twoDigit(now.getDate());
There is also padStart.m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
The code looks good and works well. Since it provides a useful bit of work, you should convert it into a function. Then you can copy that function to another program if you need so.
function yyyymmdd()
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
return yyyymmdd;
To make this code a little easier to read, you should rename x
to now
.
You could also omit the calls to toString()
, which makes the code a little shorter. Plus, you should introduce the variables mm
and dd
, so that you don't reassign to the d
and m
variables. This is a generally useful pattern, because when stepping through the code you can always look at the variable definition to see how it was computed. This is not possible for variables that change their value during execution.
The modified code looks like this:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
var mm = m < 10 ? '0' + m : m;
var dd = d < 10 ? '0' + d : d;
return '' + y + mm + dd;
Or, you could inline the last few lines:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
return '' + y + (m < 10 ? '0' : '') + m + (d < 10 ? '0' : '') + d;
That last variant is harder to read though, therefore I prefer the previous one.
Another possibility is to define a helper function that produces a two-digit string:
function yyyymmdd()
function twoDigit(n) return (n < 10 ? '0' : '') + n;
var now = new Date();
return '' + now.getFullYear() + twoDigit(now.getMonth() + 1) + twoDigit(now.getDate());
The code looks good and works well. Since it provides a useful bit of work, you should convert it into a function. Then you can copy that function to another program if you need so.
function yyyymmdd()
var x = new Date();
var y = x.getFullYear().toString();
var m = (x.getMonth() + 1).toString();
var d = x.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var yyyymmdd = y + m + d;
return yyyymmdd;
To make this code a little easier to read, you should rename x
to now
.
You could also omit the calls to toString()
, which makes the code a little shorter. Plus, you should introduce the variables mm
and dd
, so that you don't reassign to the d
and m
variables. This is a generally useful pattern, because when stepping through the code you can always look at the variable definition to see how it was computed. This is not possible for variables that change their value during execution.
The modified code looks like this:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
var mm = m < 10 ? '0' + m : m;
var dd = d < 10 ? '0' + d : d;
return '' + y + mm + dd;
Or, you could inline the last few lines:
function yyyymmdd()
var now = new Date();
var y = now.getFullYear();
var m = now.getMonth() + 1;
var d = now.getDate();
return '' + y + (m < 10 ? '0' : '') + m + (d < 10 ? '0' : '') + d;
That last variant is harder to read though, therefore I prefer the previous one.
Another possibility is to define a helper function that produces a two-digit string:
function yyyymmdd()
function twoDigit(n) return (n < 10 ? '0' : '') + n;
var now = new Date();
return '' + now.getFullYear() + twoDigit(now.getMonth() + 1) + twoDigit(now.getDate());
edited Jan 6 at 17:27
answered Jan 6 at 17:22
Roland Illig
10.4k11643
10.4k11643
There is also padStart.m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
add a comment |Â
There is also padStart.m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
There is also padStart.
m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
There is also padStart.
m.padStart(2, '0')
â Kruga
Jan 9 at 11:41
add a comment |Â
up vote
2
down vote
For getting the 0
padded date and month values, I generally follow this approach:
let d = ('0' + x.getDate()).substring(-2)
However, the Date
objects have a .toISOString
method, which returns the string in YYYY-MM-DDTHH:MM:SSZ
format, which you can split on T
and then replace -
(or vice-versa):
formatted_date = (new Date()).toISOString().replace(/-/g, '').split('T')[0]
// same as (new Date()).toISOString().split('T')[0].replace(/-/g, '')
1
Woops... This first chosen solution has just failed. A new Date() likeSun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives2018-01-06T23:26:00.445Z
resulting in20180106
instead of the expected20180107
â user157436
Jan 7 at 0:55
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function liketoLocalISOString
, which would be quite useful.
â Roland Illig
Jan 7 at 15:54
add a comment |Â
up vote
2
down vote
For getting the 0
padded date and month values, I generally follow this approach:
let d = ('0' + x.getDate()).substring(-2)
However, the Date
objects have a .toISOString
method, which returns the string in YYYY-MM-DDTHH:MM:SSZ
format, which you can split on T
and then replace -
(or vice-versa):
formatted_date = (new Date()).toISOString().replace(/-/g, '').split('T')[0]
// same as (new Date()).toISOString().split('T')[0].replace(/-/g, '')
1
Woops... This first chosen solution has just failed. A new Date() likeSun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives2018-01-06T23:26:00.445Z
resulting in20180106
instead of the expected20180107
â user157436
Jan 7 at 0:55
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function liketoLocalISOString
, which would be quite useful.
â Roland Illig
Jan 7 at 15:54
add a comment |Â
up vote
2
down vote
up vote
2
down vote
For getting the 0
padded date and month values, I generally follow this approach:
let d = ('0' + x.getDate()).substring(-2)
However, the Date
objects have a .toISOString
method, which returns the string in YYYY-MM-DDTHH:MM:SSZ
format, which you can split on T
and then replace -
(or vice-versa):
formatted_date = (new Date()).toISOString().replace(/-/g, '').split('T')[0]
// same as (new Date()).toISOString().split('T')[0].replace(/-/g, '')
For getting the 0
padded date and month values, I generally follow this approach:
let d = ('0' + x.getDate()).substring(-2)
However, the Date
objects have a .toISOString
method, which returns the string in YYYY-MM-DDTHH:MM:SSZ
format, which you can split on T
and then replace -
(or vice-versa):
formatted_date = (new Date()).toISOString().replace(/-/g, '').split('T')[0]
// same as (new Date()).toISOString().split('T')[0].replace(/-/g, '')
answered Jan 6 at 17:38
hjpotter92
4,98611539
4,98611539
1
Woops... This first chosen solution has just failed. A new Date() likeSun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives2018-01-06T23:26:00.445Z
resulting in20180106
instead of the expected20180107
â user157436
Jan 7 at 0:55
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function liketoLocalISOString
, which would be quite useful.
â Roland Illig
Jan 7 at 15:54
add a comment |Â
1
Woops... This first chosen solution has just failed. A new Date() likeSun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives2018-01-06T23:26:00.445Z
resulting in20180106
instead of the expected20180107
â user157436
Jan 7 at 0:55
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function liketoLocalISOString
, which would be quite useful.
â Roland Illig
Jan 7 at 15:54
1
1
Woops... This first chosen solution has just failed. A new Date() like
Sun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives 2018-01-06T23:26:00.445Z
resulting in 20180106
instead of the expected 20180107
â user157436
Jan 7 at 0:55
Woops... This first chosen solution has just failed. A new Date() like
Sun Jan 07 2018 00:26:00 GMT+0100
toISOString() gives 2018-01-06T23:26:00.445Z
resulting in 20180106
instead of the expected 20180107
â user157436
Jan 7 at 0:55
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function like toLocalISOString
, which would be quite useful.â Roland Illig
Jan 7 at 15:54
toISOString
always uses UTC time, and I have no idea why the API doesn't include a function like toLocalISOString
, which would be quite useful.â Roland Illig
Jan 7 at 15:54
add a comment |Â
up vote
-3
down vote
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
add a comment |Â
up vote
-3
down vote
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
add a comment |Â
up vote
-3
down vote
up vote
-3
down vote
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
yyyymmdd=x=>(f=x=>(x<10&&'0')+x,x.getFullYear()+f(x.getMonth()+1)+f(x.getDate()));
alert(yyyymmdd(new Date));
answered Jan 13 at 21:09
Eman
1
1
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f184459%2fbest-way-to-get-date-on-yyyymmdd-format%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
By the way, we are already in 2018. You wrote
20170106
. ;)â Roland Illig
Jan 6 at 17:23
To avoid those magic constants, you could also do
const components = [d.getFullYear(), d.getMonth() + 1, d.getDay()]; const paddings = [4, 2, 2]; components.map((component, i) => component.toString().padStart(paddings[i], '0')).join('');
â le_m
Jan 6 at 21:31
See also stackoverflow.com/questions/3552461/â¦
â mkrieger1
Jan 6 at 21:38
What do the fifth and sixth lines do? I'm learning JavaScript and I get the left part is a Boolean check but you're using "and" with code that sets a variable?
â BruceWayne
Jan 7 at 0:16
1
@BruceWayne if the boolean check is true, the right side statement will get executed (which here sets the variable), otherwise; if the left condition fails, it'll not execute.
â hjpotter92
Jan 7 at 6:27