문자열(String)

자바스크립트 데이터타입(자료형) 중에서 문자열( String)을 학습

📕 String(문자열)

  • JavaScript에서는 문자를 표현하기 위해서 String 데이터 타입을 이용

  • " " 또는 ' ' 사이에 문자나 숫자를 입력하면 String 데이터 타입으로 간주함

  • String은 여러가지 메서드와 프로퍼티 제공(length, toUpperCase() 등)

<h1>String 데이터 타입</h1>
<script>
  document.write('문자열 String'); // 문자열 String
  document.write('<br />'); // 개행 문자
  document.write(typeof('문자열 String')); // string
  document.write('<br />');
  document.write('문자열 String'.length); // 10
  document.write('<br />');
  document.write('문자열 String'.toUpperCase()); // 문자열 STRING
</script>
  • length는 문자열의 길이를 구하는 프로퍼티이고, toUpperCase()는 영어를 전부 대문자로 바꾸어주는 메서드

Last updated