“javascript == vs ===” Kode Jawaban

javascript == vs ===

/**
* In js :
* == it convert the variable values to the same data type before performing comparison.
* example : comparison between string and interger data type
*/
(5 == "5") // returns true

// === it does not convert data type of variable before performing comparison.
// example:
(5 === "5") // return false
Adam Al-Rahman

Perbedaan antara =, == dan === Dalam JavaScript

/*
= operator in javascript is called as assign operator. It is used to assign
value to a variable, it is used as: */
variable = "value"
/*      ^^^
here, as you can see, it is saying that variable should be assigned(=) the value
"value" */

/*
== operator in javascript is called the equals operator. It is used to compare
equals between two values, ignoring their types(number, string, boolean, etc.),
it is used as: */
   (5 == "5") // true
/* ^^^^^^^^^^
here, as you can see, it is asking that 5 is equal to "5", ignoring the type, it
returns true as their value is 5 (Note that "5" is converted to 5 for checking
for == comparator) */

/*
=== operator in javascript is called the strict equals operator. It is used to
compare euals between two values, considering their types(number, string,
boolean, stc.), it is used as: */
   (5 === "5") // false
/* ^^^^^^^^^^^
here, as you can see, it is asing that 5 is equal to "5", considering the type,
it returns false as their values is same, but their type is not (Note that "5"
is not converted into 5 for checking for === comparator) */
Pleasant Panther

== vs === JavaScript

== Equal to (1 == 1, 1 == "1") // equal in value ("1" is a string)
=== Equal value and equal type (1 === 1 but, 1 !== "1" // not equal type
Frail Flamingo

Apa yang berbeda antara tiga sama dan dua sama

false == 0    =>  true
false === 0   =>  false

0 != false    =>  false
0 !== false   =>  true
Different Dingo

== vs === JavaScript


{
    "version": "0.1.0",
    "command": "node",
    "isShellCommand": true,
    "args": [
        "--harmony"
    ],

    "tasks": [
        {
            "taskName": "runFile",
            "suppressTaskName": true,
            "showOutput": "always",
            "problemMatcher": "$jshint",
            "args": ["${file}"]
        }
    ]
}

Grumpy Giraffe

Jawaban yang mirip dengan “javascript == vs ===”

Pertanyaan yang mirip dengan “javascript == vs ===”

Lebih banyak jawaban terkait untuk “javascript == vs ===” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya