Education is the most important thing in life. It doesn’t mean that we just sit in the class and hear what your teacher says, but education is more than that. It is beyond the age, if you are more…
The original snippet, provided by Tealium, looks like any other minified JS snippet:
At first glance, it doesn’t look like there’s much room for improvement.
But what does the code really look like?
When it’s unpacked and meaningful variable names are applied, the code looks like this:
This makes it easy to understand what the snippet does.
Notice anything that could be improved yet?
There are a few things that could be improved upon, both to use less logic and less bytes.
First of all, document
isn't passed in as a parameter.
This means that the Javascript interpreter will look in the parent scope to see if it is defined there. It keeps doing this until it reaches the most outer scope. If the variable is not found, it is assumed to be global. If it doesn’t already exist, the global variable is created. This is known as “implied globals”. Passing global variables into the anonymous function as a parameters is both clearer and faster than using implied globals.
Second, assigning the URL to a variable isn’t needed.
The assignment just adds extra logic, memory usage and characters. By assigning the URL directly to…
MY BLOCKCHAIN BLOG https://press.one/main/p/bafe67db33a593ae57b98dcf43c913539162b516. “PRESSONE” is published by 南国利剑.
Car crawls rainy streets Phone has beeped a million times— Red signal, a sigh. “Respite” is published by Ambarish Chaudhari in Haiku Hub.
Science Fiction and Fantasy are hugely popular genres. What does it take for a writer today, to write compelling and successful Science Fiction and Fantasy stories? Authority Magazine started a new…