What are Javascript closures?When would you use them?

Two one sentence summaries: a closure is the local variables for a function – kept alive after the function has returned or a closure is a stack-frame which is not deallocated when the function returns. A closure takes place when a function creates an environment that binds local variables to it in such a way … Read more

How do you change the style/class on any element?

document.getElementById(“myText”).style.fontSize = “20″; (OR) document.getElementById(“myText”).className = “anyclass”; In web development, there are several ways to change the style or class of an element, depending on the specific requirements of the task and the tools being used. Here are a few common methods: Using JavaScript: JavaScript provides methods to manipulate the styles and classes of HTML … Read more

What does “1″+2+4 evaluate to? What about 5 + 4 + “3″?

Since 1 is a string, everything is a string, so the result is 124. In the second case, its 93. In JavaScript, when you use the + operator with different types of operands, it performs either addition or concatenation depending on the types involved. Here’s how the expressions you provided are evaluated: “1” + 2 … Read more

What is the difference between == and === ?

The == checks for value equality, but === checks for both type and value. In web development, especially in JavaScript, == and === are comparison operators used to compare values. Here’s the difference: == (Equality Operator): The == operator checks for equality of values after performing type coercion. Type coercion means converting the data type … Read more

Difference between window.onload and onDocumentReady?

The onload event does not fire until every last piece of the page is loaded, this includes css and images, which means there’s a huge delay before any code is executed. That isnt what we want. We just want to wait until the DOM is loaded and is able to be manipulated. onDocumentReady allows the … Read more