Wednesday, March 6, 2013

JavaScript Questions and Answers - Part 2

Continue random JavaScript Questions and Answers from previous post.

What are difference between global and local variables? 
A variable that is declare outside of a function is a global variable, and its value is accessible and modifiable throughout your program. A variable that is declared inside a function is local. It is created and destroyed every time the function is executed, and it cannot be accessed by any code outside the function. ( msdn.microsoft.com )

How we define a class in JavaScript?
JavaScript does not have a class definition separate from the constructor. Instead, you define a constructor function to create objects with a particular initial set of properties and values. Any JavaScript function can be used as a constructor. You used the new operator with a constructor function to create a new object. ( developer.mozilla.org )

What is a JavaScript function?
JavaScript function is a block of code that will be executed when it was called by external code. A function begin with the function keyword, followed by the name, list of parameters if any, and a block of codes inside a curly braces. Function can return a value. Arguments are passed to function by a value.

What is a function expression?
A function expression is a function defined inside an expression. A function name in function expression can be omitted, in which case the function is anonymous. Example: var foo = function () { return 5; }
Related posts:
JavaScript Questions and Answers – Part 2
JavaScript Questions and Answers

No comments:

Post a Comment