const life = change();

nikola

Nikola Brežnjak

Posted on March 3, 2022

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.

💖 💪 🙅 🚩
nikola
Nikola Brežnjak

Posted on March 3, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

const life = change();
javascript const life = change();

March 3, 2022