Need answers to few javascript questions? -
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
Post a Comment