글로리아-89
2024. 4. 24. 18:31
728x90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 연산자
// java의 나누기 연산자 : /(몫:정수), %(나머지)
// JS의 나누기 연산자 : /(몫:실수) %(나머지)
console.log(7/2); //JS는 3.5로 결과 반환
// Math.floor(7.2) //소수점 버리고 console에 출력
console.log(Math.floor(7.2)); //7로 반환
// 비교연산자
// java의 비교연산자 : ==, equals()
// JS의 비교연산자: ==(동등연산자), ===(일치연산자)
// != !==
// * 자동형변환
// 동등연산자: 숫자데이터와 문자열데이터를 비교할때 Number로 자동형변환
// 일치연산자: 자동형변환x, 데이터와 타입을 전부 다 비교
console.log(5 == 5);
console.log(5 =="5"); // 자동형변환
console.log(5 ==='5');
//백의 자리 이하 버리기 예제 // [num의 100자리 이하 버린 결과 : 300]
let num = 321;
// num의 100의 자리 이하 를 버린 수 console 출력
// Math.floor(num/100) = 3
console.log(Math.floor(num/100)*100);
</script>
</body>
</html>

출처: 스마트인재개발원
728x90
반응형