Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:38:02+00:00 2026-05-27T20:38:02+00:00

I saw in Crockford’s Book Javascript: The Good Parts that he does typeof comparison

  • 0

I saw in Crockford’s Book Javascript: The Good Parts that he does typeof comparison like this:

return typeof a < typeof b ? -1 : 1;

I made my own tests and I think this is the “ordering” of the different types:

function < number < object or array < string < undefined

Is this how JS actually does the comparison?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:38:03+00:00Added an answer on May 27, 2026 at 8:38 pm

    The typeof operator returns a string. String are compared by its numeric value.

    So, the < comparison order would be:

    type       charCode ("tfnosux".charCodeAt(i))   Example
    boolean     98                                   true
    function   102                                   Date
    number     110                                   123
    object     111                                   []
    string     115                                   ""
    undefined  117                                   undefined
    xml        120                                   <x></x>
    

    tfnosux are the first characters of the types. The charCodeAt method returns the numeric charCode of a character in JavaScript.

    I have added an example of each type at the previous block. Most JavaScript developers know about the first types. The final type, xml, is less commonly known, and can be obtained by using typeof on EX4.

    Demo of typeof: http://jsfiddle.net/9G9zt/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw some javaScript, like Backbone-relational written in this way: ( function( undefined )
I saw that it's possible — iBooks application does it. Is it any way
I saw some old code that had: <input type=submit name=submit onsubmit=somefunction(this) /> I was
Saw this signature today: public interface ISomeInterface<in T> What impact does the in parameter
Saw something like this in a lazily loaded property getter: public SomeClass SomeProperty {
I saw some code, html form code which looks like this: <form name=form1 method=post
Saw this option when I made a linked server
I saw in this video that computing the clustering coefficient of central node of
saw this was an error with incorrect binding (searching stackoverflow), but it looks like
I saw this example from udacity.com : def say_hi(): return 'hi!' i = 789

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.