Weird JavaScript - Part 2 π§βπ»
imsabir
Posted on February 25, 2022
Heyy!! I am JavaScript π.
Instead Weird Javascript!!
I am back with new chapter, a new weridness.
Programming is usually taught by Examples!
- Niklaus Wirth (creator of the **PASCAL **Language)
Normally, we use to follow the principle technique of development as
π Wireframing
π UI/UX Design
π HTML / CSS Development
π JS with Test case Developement
π All Good -> We are good to deliver βοΈ .
π€ͺ Not exactly same but something like this.
After 2 days: page taking long time to load.
OMG!π¨π¨ What happened?
Till yesterday everything was okay.π¨π―
Jhon investigating that and he found there are 2 functions in code and one of the function taking long time to execute.
βββ
But he also struckββ
How to find which function is taking long time to execute?
Here is JavaScript for your help
π‘π‘π‘π‘π‘ π―π―π―π―
According MDN Web Docs there is console.time()
,console.timeLog()
and console.timeEnd()
methods.
Step:
- Start the timer by writing
console.time('some-label')
with some label. -
console.timeLog('label for start timer')
will logs the current value of timer. -
console.timeEnd('label for stop timer')
will stop the timer and logs the time particular execution runs.
Just implement like below and get your leaky function. Cheers!!
π―π―π―
console.time("answer time");
// answer timer
alert("Click to continue");
console.timeLog("answer time");
alert("Do a bunch of other stuff...");
console.timeEnd("answer time");
This way Jhon can check the which function taking how much time for executing the respective task and Jhon resolved the issue.
Ongoing quiz: can you solve this javascript basic (part 1 of this series)
Don't forget to follow @msabir for more such Weird JavaScript and understanding its under the hood concepts.
Till then take care.
Posted on February 25, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.