JavaScript Greater than operation without type conversion

How would I modify this to be true without using &&(which is messy)?

7 > '3' // False

Possible there is no shortcut? No true === equivalent for greater than/less than operations?

How about:

console.log(7 > Number('3'))//true


I was looking for a way to make the statement false, currently it is true because Java automatically does type conversion. I wanted to find a way to stop this. If there isn’t an easy way than that makes sense.

I’m confused. Are you talking about Java or JavaScript?

Hi, sorry I meant javascript

So you wanna return false if two parts of the expression have different types?

Sorry let me clarify.

7 == '7' // True
7 === '7' // False


9 > '7' // True
9 >= '7' // True, But I want it to work like the line below
9 >= '7' && typeof 9 === typeof '7' // False, which is what I want to happen in the line above, but I don't know if that exists.

I don’t, my question was just whether there was an easier way of writing it.

This is actually very interesting because there’s no such thing as >==. If you found a logic to this, I suggest going with it as I don’t think there’s a common approach to this. If there is, it would be nice to know myself.

1 Like

So you want some kind of <== and >== to exist?(i have no idea for what purpose tho)
Never saw anything like that.
You can browse through list of operators:

i am having hard time trying to answer the question ‘why would i need anything like this’.

No reason, just trying to have a complete understanding of the language as I learn it.

xynoan explained what I wanted exactly. Sorry I didnt make myself very clear.

No worries. If you will run into situations where you will need some >==, share it please.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.