What is Javascript namespacing? How and where is it used?

Using global variables in Javascript is evil and a bad practice. That being said, namespacing is used to bundle up all your functionality using a unique name. In JavaScript, a namespace is really just an object that you’ve attached all further methods, properties and objects. It promotes modularity and code reuse in the application. In … Read more

What is unobtrusive javascript? How to add behavior to an element using javascript?

Unobtrusive Javascript refers to the argument that the purpose of markup is to describe a document’s structure, not its programmatic behavior and that combining the two negatively impacts a site’s maintainability. Inline event handlers are harder to use and maintain, when one needs to set several events on a single element or when one is … Read more

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