DAY9) 수의 표현(복습)

BORA·2021년 6월 6일
0

JavaScript

목록 보기
9/22

☀️ 수의 표현

보통 Subline text 도구를 사용

html 빈 문서에
html+tap을 누르면 html의 기본 샘플이 완성된다.
body 안에 script + tap 누르면 자동완성이 되고 그 안에 자바스크립트 코드를 완성화면 된다.

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<script type="text/javascript">
		alert(1);

	</script>

</body>
</html>

👉 숫자 (정수, 실수)

여기서 alert(1) <- 정수라고 칭함 (-3,-2,-1,0,1,2,3,4... 등)
실수(소수점이 존재하는 숫자, 0과 1사이에 1.1,1.2,1.3...등)

✅ 더하기

alert(1.1+1.1);

✅ 곱하기

alert(1.1*1.1);

✅ 나누기

alert(1.1/1.1);

✅ 개발자 도구에서 코드실행 시

  • alert(6/2);
    -> 3 이라고 경고참이 뜨고 출력 됨
  • console.log(6/2)
    -> 경고창이 뜨지않고 즉각 3이라고 출력 됨
  • 1
    -> 1이 출력 됨. console.log 입력 없어도 정상출력 됨
  • 1+1
    ->2라고 츨력 됨

☀️ 수의 연산

✅ 연산을 하고 싶을때는

✅ pow

Math.pow(3,2);
->9
3을 2번 제곱한 결과 출력됨

Math(카테고리)라는것 안에 pow라는 명령이 있어서 pow라는 명령을 이용해서 제곱을 사용함

✅ round

Math.round(10.6);
->11
round라는 것은 반올림

✅ celi

Math.ceil(10.2);
->11
가장 가까운 그 위에 정수로 올려줌

✅ floor

Math.floor(10.2);
->10
가장 가까운 그 아래 정수로 내려줌

✅ sqrt

Math.sqrt(9);
->3
제곱근

✅ random

Math.random();
->0.2345346
->0.3945879
랜덤한 숫자로 소수점으로 나옴

✅ 100*Math.random()

100*Math.random();
->67.34580374
->25.39483579485
100보다 작은 임의의 숫자 난수

✅ Math.round(100*Math.random())

Math.round(100*Math.random());
->89
->76
소수점이 없는 100보다 작은 임의의 숫자 난수

☀️ 문자의 표현

alert("coding everybody");
->coding everybody

alert('coding everybody');
->coding everybody

alert("coding everybody');
->syntaxError가 남 
아직 큰따움표의 문자가 끝나지 않았는데 괄호)로 끝나서 문법 에러가 남 

alert("coding everybody'");
->coding everybody'
'은 문자일 뿐 "" 로 문자가 끝남 

✅ '', ""

'' 작은 따움표: 문자
"" 큰 따움표:문자

✅ escape (문자로의 역할을 해제 시킨다)

'' 작은 따움표의 문자 안에 '를 넣고 싶을 때는 앞에 \ 를 사용한다

alert('egoing's coding everybody');
-> egoing 라고 출력 됨
그렇기 때문에 \ 사용이 필요

alert('egoing\'s coding everybody');
-> egoing's coding everybody 라고 출력 됨

✅ type of

type 확인하는 법

1
->1
숫자 data type

"1"
->"1"
문자 data type

typeof 1
->"number"

typeof "1"
->"string"

✅ 문자열(=string)

typeof "1"
->"string"

☀️ 문자에 대한 명령들

✅ \n

줄바꿈 의미로 약속됨


	<script type="text/javascript">
	alert("coding\neverybody");
	</script>

->
coding
everybody
로 출력됨

✅ +

문자끼리 더하기

<script type="text/javascript">
	alert("coding"+"everybody");
	</script>

-> codingeverybody
로 출력 됨

👉 coding 과 everybody 사이에 간격이 없음

✅ " "

" " 공백 문자를 추가 시키면 간격이 생김

	<script type="text/javascript">
	alert("coding"+" "+"everybody");
	</script>

✅ 숫자와 문자열의 덧셈 차이

숫자
1+1
->2

문자
"1"+"1"
->"11"

✅ .length

문자열(String)의 자리수 확인

"coding everybody".length
->16

✅ Indexof

code라고 하는 정보의 0,1,2,3을 나타낸다.
indexof에 입력한 어떠한 값이 c 라고 한다면, c에 해당되는 정보가 0와 같다라는 것을 알수 있다.


"code".indexOf("c")
->0
"code".indexOf("o")
->1
"code".indexOf("d")
->2
profile
Enjoy✿ 

0개의 댓글