Is this a JavaScript counter? -



Is this a JavaScript counter? -

i've seen pattern on place, i'm not sure does:

x.memb = x.memb ? x.memb + 1 : 1;

i think it's counter i'm not sure. can explain , logic?

if x.memb defined , isn't 0, increments it. in other cases, sets value 1.

it's increment taking care of case x.memb isn't defined.

you have written as

x.memb = (x.memb||0) +1;

which might more idiomatic value||defaultvalue usual build in javascript.

javascript counter

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

r - url in CRAN extension manual -

asp.net - .NET Control.ID property inconsistency -