210327 JavaScript 연산자

ITisIT210·2021년 3월 27일

JavaScript

목록 보기
3/18
post-thumbnail
<!DOCTYPE html>
<html lang="en">
    <head>
            <meta charset="UTF-8">
            <title>Document</title>
    </head>
    <boby>
        <script>
            //연산자(operator)
            //이항산술연산자 (좌항,우항)
            //+(더하기), -(빼기), *(곱하기), /(나누기), %(나머지)
            var a = 7;
            var b= 3;
            console.log(a%b);

            //단일(단항)산술연산자
            //증가연산자(++), 증감연산자(--)
            //연산자가 뒤에 오면 1씩 증가 혹은 증감
            var c = 10;
            c++; //10+1
            c++; //11+1
            c++; //12+1
            c++; //13+1
            console.log(c);

            //할당(대입)연산자
            //+=, -=, *=, /=, %=
            var d = 100;
            console.log(d+=30); //d = d + 30, d = 100 + 30, 등차수열, 등비수열
            console.log(d);

            
            var f = "100"; //문자열 100 선언
            var g = true; //true = 1, false = 0
            var h; //undefined 출력

            console.log(d+f); //130 + "100" = 130100, 암묵적 형 변환
            console.log(d+g); //130 + true(1), 131
            console.log(d+h); //NaN(NotaNumber) 연산 오류가 출력됨

            // = : 변수에 데이터를 저장하다
            // ! : 반대, 부정의 의미, Not
            //동등/일치 비교 연산자
            // ==(같다), !=(같지 않다), ===(값과 데이터의 타입까지 같다), !==(값과 데이터의 타입이 같지 않다)
            var a1 = 123;
            var a2 = 234;
            var b1 = "123";

            console.log(a1==a2); //false가 return이 됨
            console.log(a1===b1); //false가 출력됨
            
            var bool = true;
            console.log(!bool); //ture의 Not, false가 출력됨

            //대소 비교 연산자 (좌항과 우항의 비교)
            // >(크다), <(작다), >=(크거나 같다), <=(작거나 같다)
            console.log(a1>a2); //123 > 234, false

            var d1 = 132;
            var d2 = 234;
            var d3 = 345;

            //d1 < d2 < d3 여러 개의 비교 사용 불가
            //논리연산자
            // &&(And)연산자, 논리곱
            // ||(Or)연산자, 논리합
            console.log(d1<d2 && d2<d3);
            


        </script>
    </boby>
    </html>력하세요
profile
Engineering is the closest thing to magic that exists in the world.

0개의 댓글