DEV Community

imsabir
imsabir

Posted on

Weird JavaScript - Part 2 πŸ§‘β€πŸ’»

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:

  1. Start the timer by writing console.time('some-label') with some label.
  2. console.timeLog('label for start timer') will logs the current value of timer.
  3. 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");
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (1)

Collapse
 
msabir profile image
imsabir

Stay tune for more such updates