-
[Javascript] 데이터 타입- 문자열과 숫자, 변수와 대입 연산자, 웹브라우저 제어Web/Javascript 2020. 5. 16. 03:35
데이터 타입- 문자열과 숫자
-숫자
콘솔 경고창에 숫자 표현하기: alert(1)
콘솔 경고창에 숫자 표현하기 2: alert(1+1)
콘솔에서 덧셈하기: 1+1
산술 연산자: +,-,*,/
-문자열
따옴표나 작은따옴표로 이루어져 있음
.length와 같은 것들을 프로퍼티라고 함
문자열을 대문자로 출력하기: '문자' .touppercase()
문자열에서 특정 문자 찾기
'hello world' .indexof('0') ---- -1로 찾을 수 없다는 결과가 나옴
'hello world' .indexof('o') --- 4가 나옴. 'h'부터 0으로 쳐서 4번째 자리에 소문자 'o'가 나온다는 뜻
'hello world' .indexof('world') 공백을 포함헤서 6번째에 'world' 라는 문자열이 시작함
문자열에서 공백 제거하기:
' hello ' -------- 공백이 그대로 출력
' hello ' .trim() ----> 공백을 없애고 출력
숫자와 문자열
1+1 ----------- 2
'1'+'1' ---------- '11'
코드에서 black을 ' ' 로 감싸고 있음. 즉 'black'은 문자열. white와 body도 마찬가지.
변수와 대입 연산자
변수: 바뀔 수 있는 값
상수: 바뀌지 않는 값. 1, 2, 3 ...
x= 1;
y= 1;
x+y; -------------2
x=1000;
x+y; --------1001
문자열의 문자 바꾸기
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' .indexOf('egoing')
name='aeong';
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor aeong ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
변수를 사용할 때 var라는 키워드를 변수 앞에 써주기 (변수 선언)
var name='aeong';
대입 연산자를 통해 'black'이 backgroundcolor라는 변수의 값이 됨.
웹브라우저 제어
웹 페이지에서 night 버튼을 눌렀을 때 배경색을 검은색으로 바꾸고, 글씨색은 흰색으로 바꾸기
<body> 태그에 style 속성을 쓰고, style 속성의 값을 지정.
즉, night 버튼을 클릭했을 때 이 웹 페이지에 있는 <body> 태그의 스타일 속성을 바꾸면 됨.
www.evernote.com/l/AlcUWB1oa0RNgptEXG5HvldQdVctSNxuW7M/
데이터 타입- 문자열과 숫자, 변수와 대입 연산자, 웹브라우저 제어
데이터 타입- 문자열과 숫자 -숫자 콘솔 경고창에 숫자 표현하기: alert(1) 콘솔 경고창에 숫자 표현하기 2: alert(1+1) 콘솔에서 덧셈하기: 1+1 산술 연산자: +,-,*,/ -문자열 따옴표나 작은따옴표로 이루
www.evernote.com
'Web > Javascript' 카테고리의 다른 글
[Javascript] 객체 예고 (0) 2020.05.16 [Javascript] 함수 (0) 2020.05.16 [Javascript] 배열과 반복문 (0) 2020.05.16 [Javascript] 제어할 태그 선택하기, 비교 연산자와 불리언, 조건문, 리팩터링 (0) 2020.05.16 [Javascript] 야간 모드, <script> 태그, 이벤트, 콘솔 (0) 2020.05.16