1.

Which of the two lines of code below is more efficient and why?

Answer»

document.getElementById("interviewBit"); OR $("#interviewBit");

  • The code document.getElementById( "interviewBit" ); is more efficient because its the pure JavaScript version.

  • The reason being jQuery is built on top of JavaScript and internally uses its methods to make DOM manipulation easier. This introduces some performance overhead. We need to remember that jQuery is not always better than pure JavaScript and we need to use it only if it adds advantage to our project.




Discussion

No Comment Found