Re: Newbie: When to use typeof() function

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



string is just a *keyword* that express a type. typeof allows to return a
*variable* that symbolizes this type *name*.

Don't see this as returning the "type of a type" but as returning a type
variable for a type "literal" mentioned in your source code....

--
Patrice

"GiJeet" <gijeet@xxxxxxxxx> a écrit dans le message de groupe de discussion
: cd88b635-14b0-4587-a38b-1c4a47a9fbff@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 22, 8:11 am, Family Tree Mike
<FamilyTreeM...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
"GiJeet" wrote:
Hello, I see the use of typeof() function often when I'm reading code
but I'm not sure when I would need to use it. I understand it returns
the type of a type. huh? It's kind of confusing. Can someone provide
an example of when I would need to know the type of something and
would need to use typeof(). Thanks.

Thanks for the examples but I guess now my question is WHY do I need
to get the type of a type? Is it a run-time thing? I mean, we know
the types at design time.


.



Relevant Pages

  • Re: hiding javascript function call from status bar.
    ... Using "unselectable" The the user can still select it, but a selection ... anything I haven't tested to death on host objects (e.g. typeof.) ... The Safari developers had typeof style.filter ... you would expect a string. ...
    (comp.lang.javascript)
  • Re: Best test for undefined?
    ... But isn't strict comparision faster than loose comparision? ... (the steps which are essential for our case -- when operands have _the same_ types such as in mentioned `typeof` check): ... because in our case types are equal -- we have String type. ... let us don't call == as a "bad practice" and don't say that this is about avoiding errors and etc. arguing _logically_. ...
    (comp.lang.javascript)
  • Re: hiding javascript function call from status bar.
    ... Assuming a pointing device is used, in most browsers that would be the ... Because host objects are specified to be unpredictable. ... Using typeof ... even though it is a string value. ...
    (comp.lang.javascript)
  • Re: hiding javascript function call from status bar.
    ... anything I haven't tested to death on host objects (e.g. typeof.) ... The - in - operator has worked reliably on host objects for me for the last 2 years. ... Opera says the empty string: ... It is more of an enhancement, though, to make it so that if the user clicks on your widget, that it won't start a selection if the mouse moves. ...
    (comp.lang.javascript)
  • Re: When is a function not a function?
    ... would yield "string", so the test ... typeof fn!= "string" ... fn.constructor!= Array ... could not yield `true' and therefore that test would be unnecessary as well? ...
    (comp.lang.javascript)