Need answers to few javascript questions? -


https://stackoverflow.com/questions/1684917/what-questions-should-a-javascript-programmer-be-able-to-answer

i need few answers questions posted here?.

i'm iterating through array defined, has 3 elements in it.. numbers 1 2 , 3.. why on earth jack showing up?

object.prototype.jack = {};  var = [1,2,3];  ( var number in ) {     alert( number ) } 

why alert undefined when declared jack variable 'jack'?

<script>     (function() {         var jack = 'jack';     })();     alert(typeof jack) </script> 

why object , not array? how detect if array?

array = [1,2]; alert( typeof array ) 

i have 2 strings, second evaluation doesn't become true. potential bug? how come it's not true?

alert( [typeof 'hi' === 'string', typeof new string('hi') === 'string' ]  ) 

for first question, for-in construct in javascript intended iterate on object properties. since have added jack prototype of objects, appear. proper way iterate array in javascript incremental loop

for (var i=0; i<a.length; i++) {   console.log(a[i]); } 

for second question, declared var jack in scope of anonymous function. isn't known alert outside.

// declare outside. var jack; (function() {     jack = 'jack'; })(); alert(typeof jack); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -