0

I am new to learning JavaScript,I found this code, I had learnt earlier that equality is checked using 3 equal symbols, so shouldn't this program crash(it doesn't surprisingly)

/*jshint multistr:true */

text = "Blah blah blah blah blah blah Eric \
blah blah blah Eric blah blah Eric blah blah \
blah blah blah blah blah Eric EdiEk";

var myName = "Eric";
var hits = [];

// Look for "E" in the text
for(var i = 0; i < text.length; i++) {
    if (text[i] == "E") {
        // If we find it, add characters up to
        // the length of my name to the array
        for(var j = i; j < (myName.length + i); j++) {
            hits.push(text[j]);
        }
    }
}

if (hits.length === 0) {
    console.log("Your name wasn't found!");
} else {
    console.log(hits);
}

The program checks if your name or something similar to it is in the text[]

  • No, why would it need to use a type-strict operator? You already know that both `text[i]` and `"E"` are strings. – Bergi Jun 10 '14 at 11:00
  • Actually, this program checks whether the letter "E" is in the text and prints out a series of all 4-letter segments starting with "E". – JLRishe Jun 10 '14 at 11:32

1 Answers1

0

No, it would not crash. == as well as === are both equality operators, differing only in strictness.

1 == "1"
true
1 === "1"
false
1 == true
true
1 === true
false
0.00 == false
true
0.00 === false
false
DhruvPathak
  • 42,059
  • 16
  • 116
  • 175