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 8438831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:49:33+00:00 2026-06-10T07:49:33+00:00

I was explaining to a colleague that you should use === and !== (and

  • 0

I was explaining to a colleague that you should use === and !== (and >== and <== of course) when comparing variables in JavaScript so that it doesn’t coerce the arguments and get all froopy and confusing but they asked me a two part question that I did not know the answer to and thought I would ask the experts here, specifically it is:

What about > and < – when they compare do they also coerce the arguments or not – why isn’t there some sort of >> and << operator (probably need to be some other syntax as I would guess they would be bit shift operators if it is going along the whole C style but you get the gist)?

So I can write a test to find the answer to the first part, which I did, here it is:

// Demo the difference between == and ===
alert(5 == "5");
alert(5 === "5");   

// Check out what happens with >
alert(5 > "4");    
alert(5 > 4);

and it returned:

true
false

true
true

so it does look like the > is doing the coercion since > "4" and > 4 return the same result. so how about the second part…

Is there some sort of operator for > and < that do not coerce the type (or how can I change my test to perform the test safely)?

  • 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-06-10T07:49:35+00:00Added an answer on June 10, 2026 at 7:49 am

    No, there’s no need for such operators. The type checking done for those relational operators is different than for equality and inequality. (edit — perhaps it’s a little strong to say that there’s “no need”; that’s true only because JavaScript deems it so 🙂

    Specifically, the > and < and >= and <= operators all operate either on two numeric values, or two strings, preferring numeric values. That is, if one value is a number, then the other is treated as a number. If a non-number can’t be cleanly converted to a number (that is, if it ends up as NaN), then the result of the comparison is undefined. (That’s a little problematic, because undefined will look like false in the context of an if statement.)

    If both values are strings, then a collating-order string comparison is performed instead.

    If you think about it, these comparisons don’t make any sense for object instances; what does it mean for an object to be “greater than” another? I suppose, perhaps, that this means that if you’re finding yourself with values of variant types being compared like this, and that’s causing problems, then yes you have to detect the situation yourself. It seems to me that it would be good to work upstream and think about whether there’s something fishy about the code that’s leading to such a situation.

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

Sidebar

Related Questions

When explaining Clojure builds, I would like to use the correct terminology. Therefore my
Is there a documentation explaining android Stagefright architecture? Can I get some pointers on
Let me start with explaining what I mean with magic. I will use two
I've read several articles explaining the use of static classes in a MVC webapplication.
The title is all-explaining I think. I want to develop .Net GUI application for
I was explaining to our SEO specialist that cakephp url structure is domain/controller/view/params so
Before I start explaining the code I will first give my use case so
For pupose of explaining let's say that I have a Company object which has
How do I go about explaining that I am a Web Application Developer and
I remember reading a style guide explaining what the proper line-height should be for

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.