Profile image of Greentonic
Submitted by Greentonic
over 12 years

What does two equal signs (==) mean?

In this part here: if (text[i] == “T”){ for (var j=i; j<(myName.length+ i); j++){ hits.push(text[j]);

Under what condition do you use ==?

Answer 51c6b97a9c4e9df8e50184a6

1 vote

Permalink

That is the ‘equal to’ sign sign. It’s called an ‘comparison operator’.

e..g. text.length == text.length OR text.length == 4 OR 5 + 10 == 15

As far as I know, comparison operators are used with Booleans(True or False data type) to determine whether or not a block of code should run. You’ll often see them in ‘if statements’. e.g.

if (6 == toffee.length) { return “This is true”; }

else { return “This is incorrect”; }

There are other comparison operators: < Less than

Greater than <= Less than but equal to = Greater than but equal to == Equal to != Not equal to

There is also another Equal to comparison operator. It is === . It’s evil twin would be !== (Not equal to).

You DO NOT use == or === when declaring a variable.So something like:

var myName == Toffee; is a big no no and this will explain why you’ll see ‘** for (var j=i;**’ instead of ‘for (var j==i;’ in line 3.

Sorry for the typos; in a hurry.

Profile image of Groudie
Submitted by Groudie
over 12 years

3 comments

Profile image of haxor789
Submitted by haxor789
over 12 years

The difference between == and === is that == compares if the values are equal e.g. 1 = “1” would be true whereas === compares values and types e.g. 1=”1” would be false.

Profile image of Greentonic
Submitted by Greentonic
over 12 years

Thank you Groudie and Haxor!

Profile image of cflingo
Submitted by cflingo
over 12 years

I was wondering the same thing. Thanks for the ? Toffee.

Popular free courses

  • In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
    • Beginner Friendly.
      4 Lessons
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      11 Lessons
  • Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
    • Beginner Friendly.
      6 Lessons
Explore full catalog