What is the difference between = and ==?

后端 未结 4 1989
孤独总比滥情好
孤独总比滥情好 2020-12-03 19:52

What is the difference between = and ==? I have found cases where the double equal sign will allow my script to run while one equal sign produces a

4条回答
  •  Happy的楠姐
    2020-12-03 20:24

    In the simplest of terms, take these two lines of code for example:

    1) x = 10
    2) x == 10

    The first line (x = 10) means "I am commanding that x is equal to 10."

    The second line (x == 10) means "I am asking the question, is x equal to 10?"

    If you write "x == 10" first, it will give you an error message and tell you that x is not found.

    If you write "x = 10," this will store x as 10.

    After you have written "x = 10", then if you write "x == 10," it will respond "TRUE", as in "yes, x does equal 10, because you made x equal to 10." But if you write "x == 11" or "x == 12" or x == anything besides 10, then it will respond that "FALSE," as in "no, x does not equal 11 or 12 or anything besides 10, because you made x equal to 10."

提交回复
热议问题