What is "===" (triple equal)?

I swear I saw when scrolling on some forum some 10 minutes ago some code that had something like

a === b 

and at the time, I only took a mental note of me reading that, but it didn't occur to me that I have never seen that before, and i have no idea what it is, and after a while, I looked it up but can't find anything on it. I can't find the particular forum page in my browser's history. What is that triple equal used for? if I recall correctly, it was in the argument of an "if".

Did you try if the compiler accepts it ?
There must be another character somewhere.
For example:

if(a=x==b)
if(a==b==c)
if(a=b==2?x==1:c==2)

I have not tried to compile it, I don't remember the full code, I just remember seeing the triple equal sign and thought it was strange. I don't remember much else, except I'm pretty sure I saw it written like that in two separate places in that guy's code, and there were no other characters between the equal signs, just "===" used in place of a comparison operator(?).

Perhaps you were looking at javascript code? It is VERY similar to c++, and does have a === operator.

1 Like

You have to come with proof that it is used somewhere. I don't think so.

It seems to be possible in JavaScript, HTML and a number of other (script) languages.

I don't think that a C++ compiler would have the non-standard triple equal.

Why not compile a simple test sketch that uses it?

I got an error:
expected primary-expression before '=' token

...That was easy!

Easy ? this is easy:

void setup() 
{
  Serial.begin(9600);
  Serial.println("How to get triple equal in a sketch");
  Serial.println("===");
}

void loop() {}

Sorry for my cheesy post, I'm half asleep.

3 Likes

uh-oh, I can see this becoming an exercise in futile complexity soon..!

How many lines of obfuscated code to generate three equal signs.

1 Like

In JavaScript you are using === for a strict comparision.

if(typeof jo['cir'+i]==='undefined')

read more here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality

and

I think it could have been javascript, now that you mention it.

I think it was, now that you mention it.

Because I don't know how it was used, and I don't have the original sketch?

I think it was javascript rather than C++ code, thanks for your input!

You don't know how the actual thing was used in the original sketch, so you trying to compile something isn't gonna cut it. But, in the meantime, i found the answer. I may have seen JavaScript code rather than C++ code

Yep, I think that's exactly what happened. Thanks!

If it fails to compile and produces an error, then the rest of the sketch doesn't matter, does it?

you know there is a quicker and more efficient way to search for answers

yeah but I initially thought this operator was from C++ and couldn't find anything on it. (hence I posted my question on this forum). Read the original post before commenting.

This stupid operand could not exist in C++ as C++ is strongly typed language, not like that abomination people call JavaScript.

1 Like