Difference between revisions of "Interview Questions"

From Hawk Wiki
Jump to: navigation, search
(Object-oriented programming)
(Object-oriented programming)
Line 3: Line 3:
 
==Object-oriented programming==
 
==Object-oriented programming==
 
Check here [[Interview_Questions(OOP)]]
 
Check here [[Interview_Questions(OOP)]]
 +
==JavaScript==
 +
Closure.
 +
<pre>
 +
<script>
 +
function say667() {
 +
  // Local variable that ends up within closure
 +
  var num = 666;
 +
 
 +
  //var sayAlert = function() { alert(num); }
 +
  return function() { num++; alert(num); };
 +
}
 +
 +
var sayNumba = say667();
 +
sayNumba();
 +
sayNumba();
 +
</script>
 +
</pre>
 +
The example will keep var num in the memory. alert 667 and 668 on each call;

Revision as of 23:48, 16 February 2012

Some Translation

n! Multiplicative

Object-oriented programming

Check here Interview_Questions(OOP)

JavaScript

Closure.

<script>
function say667() {
  // Local variable that ends up within closure
  var num = 666;
  
  //var sayAlert = function() { alert(num); }
  return function() { num++; alert(num); };
}

var sayNumba = say667();
sayNumba();
sayNumba();
</script>

The example will keep var num in the memory. alert 667 and 668 on each call;