보통 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);
Math.pow(3,2);
->9
3을 2번 제곱한 결과 출력됨
Math(카테고리)라는것 안에 pow라는 명령이 있어서 pow라는 명령을 이용해서 제곱을 사용함
Math.round(10.6);
->11
round라는 것은 반올림
Math.ceil(10.2);
->11
가장 가까운 그 위에 정수로 올려줌
Math.floor(10.2);
->10
가장 가까운 그 아래 정수로 내려줌
Math.sqrt(9);
->3
제곱근
Math.random();
->0.2345346
->0.3945879
랜덤한 숫자로 소수점으로 나옴
100*Math.random();
->67.34580374
->25.39483579485
100보다 작은 임의의 숫자 난수
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'
'은 문자일 뿐 "" 로 문자가 끝남
'' 작은 따움표: 문자
"" 큰 따움표:문자
'' 작은 따움표의 문자 안에 '를 넣고 싶을 때는 앞에 \ 를 사용한다
alert('egoing's coding everybody');
-> egoing 라고 출력 됨
그렇기 때문에 \ 사용이 필요
alert('egoing\'s coding everybody');
-> egoing's coding everybody 라고 출력 됨
type 확인하는 법
1
->1
숫자 data type
"1"
->"1"
문자 data type
typeof 1
->"number"
typeof "1"
->"string"
typeof "1"
->"string"
줄바꿈 의미로 약속됨
<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"
문자열(String)의 자리수 확인
"coding everybody".length
->16
code라고 하는 정보의 0,1,2,3을 나타낸다.
indexof에 입력한 어떠한 값이 c 라고 한다면, c에 해당되는 정보가 0와 같다라는 것을 알수 있다.
"code".indexOf("c")
->0
"code".indexOf("o")
->1
"code".indexOf("d")
->2