DevPrep

All topics › The Swift Language

== vs === — what's the difference?

Junior PRO

The idea

final class Node: Equatable {
    let value: Int
    init(_ value: Int) { self.value = value }
    static func == (l: Node, r: Node) -> Bool { l.value == r.value }
}

let a = Node(1), b = Node(1), c = a
print(a == b, a === b, a === c)   // true false true

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store