자바스크립트 투쟁 - 4부 | 비교

다시 시작합니다!





이것은 매우 쉽지만 우리 모두는 그것을 알아야 합니다. 당신은 이미 다른 곳에서도 그것에 대해 들었을 것입니다.
JS의 비교 방식에 익숙하지 않다면 계속 진행하십시오. 그렇다면 이 게시물은 당신을 위한 것이 아닙니다. 😊👏🏻

JavaScript에서 변수를 비교하는 두 가지 방법이 있습니다.
  • Two Equal Signs (==)
  • Three Equal Signs (===)

  • 두 개의 등호(==)

    Most majority of programming languages uses == as the one and only comparing operator, but in JavaScript we're special. 😏

    == is only comparing the value of the variable, ignoring the data type of it; so if there's a number that is equal to a number inside the string it'll always be true.

    E.g.

    console.log('0' == 0); // Outputs: true
    
    console.log(1 == true); // Outputs: true
    

    The data type of the variable will not be changed after the comparison

    Some of Its Uses
    We can use it to check if the number is not 0 or an empty string.
    let num = 0;
    let word = "";
    
    console.log(num == true); // Outputs: false
    console.log(word == true); // Outputs: false
    
    num = 5;
    word = "Hey!";
    
    console.log(num == true); // Outputs: true
    console.log(word == true); // Outputs: true
    


    3개의 등호(===)

    We use this as the normal comparing operator, that's only working with JavaScript, TypeScript, PHP.

    What === actually does is that it compares the value and the data type.

    E.g.

    console.log("0" === 0); // Outputs: false
    
    /* They must be of the same data type. */
    console.log("0" === "0"); // Outputs: true
    

    === is the most used one. Probably because it's the easy way of conparing and we all understand it even if JavaScript wasn't your first language.


    읽어 주셔서 감사합니다! 😌 이것이 누군가에게 도움이 되기를 바랍니다.



    좋은 웹페이지 즐겨찾기