Tutorial by Examples

typeof is the 'official' function that one uses to get the type in javascript, however in certain cases it might yield some unexpected results ... 1. Strings typeof "String" or typeof Date(2011,01,01) "string" 2. Numbers typeof 42 "number" 3. Bool typeo...
When one with typeof operator one gets type object it falls into somewhat wast category... In practice you might need to narrow it down to what sort of 'object' it actually is and one way to do it is to use object constructor name to get what flavour of object it actually is: Object.prototype.toSt...
To find whether an object was constructed by a certain constructor or one inheriting from it, you can use the instanceof command: //We want this function to take the sum of the numbers passed to it //It can be called as sum(1, 2, 3) or sum([1, 2, 3]) and should give 6 function sum(...arguments) {...

Page 1 of 1