DEV Community

Cover image for const life = change();
Nikola Brežnjak
Nikola Brežnjak

Posted on

2 1

const life = change();

They (supposedly, originally, Heraclitus) say that the only true constant in life is change.

A JavaScript programmer in you might write that like this:

const life = change();
Enter fullscreen mode Exit fullscreen mode

And, the trick in real life is that the function's implementation regularly looks like this:

function change() {
    return Math.random();
}
Enter fullscreen mode Exit fullscreen mode

However, when you'd try to output the value of the life constant (see it in action in JS Fiddle), it would be exactly that, a constant (no matter how many times you'd call it or output it).

Sidenote: if you're puzzled by the fact that you can assign a function to a constant (or to a variable for that matter) before it was defined in the code, then go and learn about hoisting in JavaScript.

Now, you may write the above statement like this:

const life = function change() {
    return Math.random();
}
Enter fullscreen mode Exit fullscreen mode

And, if you call life(); now (again, see it in action), it will return a different value every time you call it.

⚠️ JavaScript gurus among you may chuckle at assigning a function to a constant, but check this StackOverflow answer for its applicability - plus, you'll learn (or, refresh your memory) about hoisting in JS.

Switching gears; the point of all this is that you can't expect to be doing the same thing, and getting different results, and no matter what obstacles you face, the key to overcoming them is not in changing the event, but in changing yourself and how you react to it.

And that, itself, is a process. A process that begins with the desire or acceptance to be teachable and improve for the better.

Hope you like this attempt at mixing programming with personal growth topics (for more, check my daily thoughts entries).

Stay safe, friends ❤️


Originally published on my blog.

This is why I write these 'daily thoughts' posts.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay