Difference between “ == “ and “ === “ operators

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Diff b/w == vs ===</title>

</head>

<body>

<input type="text" id="InputValue" name="InputValue">

<button onclick="checkFunc()">Click Here</button>

<script>

function checkFunc() {

    const newArray = [1,2,3,4,5,6,7,8,7,2,1,3,5,6,4,3,6,45,65,34,1,1,2,2];

let InputValue = document.getElementById('InputValue').value;

const filterValue = newArray.filter(v=>v==InputValue)

const findValue = newArray.find(v=>v==InputValue)

if(findValue===InputValue){

    // Returns false since the typeof findValue is "number" and typeof InputValue is "string"

console.log('false',InputValue)

} else if(findValue==InputValue){

  // Returns true since the value of both findValue and InputValue is the same

console.log('true',InputValue)

}

}

</script>

</body>

</html>





No comments:

Post a Comment

SQL Commands - essentials

  SELECT # Retrieve data from the database FROM # Specify the table to select data from WHERE # Filter rows based on a condition AS # Rename...

Best for you