jhcloos.github.io
jhcloos.github.io copied to clipboard
removed years on copyright
the copyright will still be valid, and you won't need to keep on updating the year
If we use a little bit of JavaScript, we can make the year dynamic.
const date = new Date()
const year = date.getUTCFullYear() // this gives you the current year
const text = `Copyright © 2004 - ${year}`
Oh that'd be cool
Couldn't it be simplified to
const date = new Date()
const text = `Copyright © 2004 - ${date.getUTCFullYear()}`
I don't know much Javascript, so please correct me if I'm wrong
That would depend on what we mean by "simplified."
For instance, we could write our solution like this
const text = `Copyright © 2004 - ${(new Date()).getUTCFullYear()}`
This fits into one line, but is it simplified? 🤷🏽
Perhaps a better way to think of writing code is its ease of readability for humans. Consider the next example,
const date = new Date()
const currentYear = date.getUTCFullYear()
const text = `Copyright © 2004 - ${currentYear}`
While there is a lot more code to read, we might say that it's actually easier to read. This is a matter of style, since both code examples work perfectly.
Though this is a trivial example, you can imagine a complex codebase might contain thousands of lines of code. In such a scenario, it makes a big difference when code is written in a clear and concise manner.
Hope that helps!
Hmm. You seem like a smart person, I think I'll add your suggestion
Thanks 👍 for polling