Questions tagged [triple-equals]

The triple-equal operator (===) refers to objects that are both equal and of the same type.

The triple-equal operator (===) refers to objects that are both equal and of the same type.

The languages JavaScript and PHP uses this syntax, with the == operator able to return true if two values are equal, even if they have different types (for example, "4 == "4"" is true), and the "===" operator returning true only if two values are equal and have equivalent types as well (such that "4 === "4"" is false but "4 === 4" is true). [1]

18 questions
18
votes
1 answer

How do I do a strict equals/triple equals comparison in phpunit?

How do I do a ===/strict equals comparison in phpunit?
Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
14
votes
2 answers

Can I use triple equals for JavaScript string comparison?

This is an extremely basic question, I know, but I couldn't understand what's going on from Google and Stack Overflow. I looked here and here to learn how to compare strings in JavaScript. Neither mentioned triple equals (===) in their answers, and…
Neta
  • 871
  • 5
  • 14
  • 30
8
votes
5 answers

Meaning of === with function call

I had been going through the ES6 assuming that it would be easy to switch to EcmaScript 2017. While going through, I got confused about this code function f (x, y = 7, z = 42) { return x + y + z } f(1) === 50 Which has ES5 equivalent function…
Tirthraj Barot
  • 2,671
  • 2
  • 17
  • 33
4
votes
7 answers

! next to a number in a conditional prints true on strict comparison

console.log(false === 0) // false console.log(false === !1) // true, why does it equate to true using !? and vice versa for console.log(true === 1 ) // false console.log(true === !0) // true I understand the difference between equality and…
4
votes
2 answers

JavaScript triple equals and three-variable comparison

Can somebody explain this? 1 == 1 //true, as expected 1 === 1 //true, as expected 1 == 1 == 1 //true, as expected 1 == 1 == 2 //false, as expected 1 === 1 === 2 //false, as expected 1 === 1 === 1 //false? <-- Also is there a name…
user1318194
4
votes
3 answers

Javascript idiom: What does if (x === +x) do?

Reading through the source code of underscore.js I stumbled upon the following line: ... if (obj.length === +obj.length) { ... That's a bit confusing for me. What is actually being compared here? I believe it has something to do about detecting…
Saintali
  • 4,482
  • 2
  • 29
  • 49
2
votes
1 answer

PHP - Are empty arrays considered as null

The following code gives TRUE,FALSE,FALSE,FALSE, I dont understand the TRUE response on empty arrays. Someone has an explanation? $results=array(); // Case 1 : Empty array $myArray=array(); array_push($results,…
tit
  • 599
  • 3
  • 6
  • 25
2
votes
1 answer

Javascript comparisons == null alternatives

In JavaScript code I want to replace the double-equals structure of the following if-statement: if( name == null ) { //do stuff } The double equals fail for the jshint rule "eqeqeq", where it's recommended to replace double equals with triple…
Jesper Rønn-Jensen
  • 106,591
  • 44
  • 118
  • 155
1
vote
4 answers

Are there any triple equals === methods outside of Cats in Scala?

I have spent a while searching on Google for a non-Cats triple equals method, but can't find anything apart from Scalaz. Unfortunately, I have been unable to work out the import for === in this library. Can someone help, many thanks.
J Hubbard
  • 107
  • 1
  • 11
1
vote
1 answer

2 equalities on an IF conditional like in python

I'm starting to learn javascript for front-end programming, being python my first language to learn completely. So I'm trying to solve a while loop excersise that console-logs every number from 50-300 that is divisble by 5 and 3. So in python i…
1
vote
1 answer

How to perform triple equals as negation

I am learning scala, and want to write my tests with ===. However, I am curious if there is a way to do something like this: assert(1 !=== 2) I have tried the above, !==, and !(===) Is there any way to get the descriptiveness of === and use…
Justin Pihony
  • 66,056
  • 18
  • 147
  • 180
0
votes
0 answers

does javascript equality for 2.0 === 2 - hold true for all browsers

I want to write a function to trim additional decimal 0's from floating point numbers like 2.0, 5.00 but not 3.04. so I wrote this: const trimZeroFromDecimal = value => parseInt(value) === value ? parseInt(value) : value; but will this equality…
Probosckie
  • 1,585
  • 4
  • 25
  • 40
0
votes
0 answers

FMOD in PHP results not being seen as equal to their float equivalent

So I understand that FMOD gives some wacky answers sometimes because its sort of approximate. But even given that I'm struggling to utilize the answers it throws up later-on in the code. For instance, fmod(16,1.6) gives us 1.6 rather than 0, that's…
0
votes
1 answer

Javascript checking, if array element equals var?

I have an array like this: var str = "This is an example sentence with the number 1"; var array = str.split(' '); // array[8] should be 1 Now i want to check, if a certain variable is the same as the value of array[8]. Therefor i thought I could…
Frosty
  • 41
  • 1
  • 6
0
votes
0 answers

Which other literal values apart from NaN - are not equal to themselves

It's a known fact in Js that the value NaN is not equal to itself console.log(NaN === NaN) // false Which other Javascript literal values are not equal to themselves - or is NaN the only value?? I've already checked and found that undefined, null,…
Probosckie
  • 1,585
  • 4
  • 25
  • 40
1
2