We have multiple methods in javascript to write code for checking conditions and looping in javascript, but you may be unaware that, that method is not an optimized way to use there.
if you want to check performance between different approaches, you can use the following ways to find optimized code between or among themes.
Console.time()
console.time() starts counting the time when your code starts running and you can use console.timeEnd it gives the duration your code takes time to execute that code. so using this method you can compare your code which is the optimized code.
console.time("for loop");
for (let i = 0; i < 1000000; i++) {}
console.timeEnd("for loop");
let i = 0;
console.time("while loop");
while (i < 1000000) {
i++;
}
console.timeEnd("while loop");
console.timeEnd()
console.timeEnd() is the end time of code execution from where you are watching the time by console. time().