자바스크립트 기초2

아주그냐앙·2022년 7월 15일
0

자바스크립트 문법

문자열 합치기

str.concat(str2)
str.concat("world")
'helloworld'
str+str2
'helloworld'

문자열 인덱싱

str.cahrAT(x)
str.[x]




### 배열에 추가 

.push(element) : 배열의 뒤에 엘리먼트 추가
.pop() : 배열의 뒤에서 엘리먼트 삭제하고 리턴
.shift() : 배열의 앞에서 엘리먼트 삭제하고 리턴
.unshift(element) : 배열의 앞에 엘리먼트 추가

정수 변환 parseInt

var height = "160.4";
console.log(height, typeof(height));    // 160.4 string이 출력됩니다.
var height_int = parseInt(height);
console.log(height_int, typeof(height_int));    // 160 'number'가 출력됩니다.

연산자

 제곱 연산자
Math. pow (2,3);
8 
제곱근
Math.sqrt(16);
4
Math.random();
0.1231145125 (0에서 1까지에 랜덤 숫자)

&& and연산자
||    or연산자
'''

0개의 댓글