본문 바로가기
IT/JavaScript

ES5 문법 #2 ~ string

by 2T1 2022. 12. 13.
 

ES5 문법 #1

ECMAScript 2009의 주요 문법 정리 2009년의 가장 첫번째 개정판. ES5라고도 불림 Features "use strict" String[number] access Multiline strings String.trim() Array.isArray() Array forEach() Array map() Array filter() Array reduce() Array r

who-is-2t1.tistory.com


use strict

“use strict”은 JavaScript 코드를 strict 모드에서 사용되어야 한다는 것을 정의한다.

엄격모드에서는 선언되지 않은 변수를 사용할 수 없다.

 

JavaScript "use strict"

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

Property Access on String

charAt() : return the character at a specified index in a string. string 에서 특정 index의 글자를 반환한다.

var str = "Hello"
str.charAt(1);    //return e

ES5 문자열의 속성 접근을 허용한다.

 var str = "Hello"
str[1];   //return e

이외의 문자열 속성 함수 참고

 

JavaScript String Methods

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

String Over Multiple Lines (여러줄에 걸쳐 String 사용하기)

var str = "Hello 
World";      //error

var str1 = "Hello \\
World";     //str = "Hello World"
//오래된 브라우저는 \\ 뒤의 공백을 허용X. 
//보편적으로 지원되지 않으니 사용시 주의

var str2 = "Hello " + "World";
//가장 보편적으로 사용하는 방법

 

Reserved Words as Property Names

예약어를 속성 이름으로 사용

var obj = {name : "M.Lee", new : true}
obj.new    // return true

 

string trim() (앞 뒤 공백 제거)

var str = "            He llo     "
str.trim()          //return "He llo"

 

'IT > JavaScript' 카테고리의 다른 글

JavaScript 번들러  (0) 2022.12.26
ES5 문법 #4 ~ JSON, Date, Object...  (0) 2022.12.15
ES5 문법 #3 ~ Array  (0) 2022.12.14
ES5 문법 #1  (0) 2022.12.13
JS Versions (JavaScript Versions)  (0) 2022.12.13