[javascript] programming with javascript part 1에서 리마인드할 만한 내용들
2021-11-26
programming with javascript part 1
11-02 학습건
variables
- 변수는 애플리케이션에서 한번 쓰고 버리는 값이 아닌 값이 아닌 일정 기간 유지할 필요가 있는 값에 사용한다. 또한 변수를 사용하면 값의 의미가 명확해져서 코드의 가독성이 좋아진다.
- 변수의 존재 목적을 쉽게 이해할 수 있도록 의미있는 변수명을 지정하여야한다.
-
Re-declaring javascript variables
재선언할 때, 이전에 할당된 데이터는 여전히 남아있다.
var carName = "Volvo"; var carName console.log(carName); // Volvo 출력 - 원시타입의 데이터타입 (primitive data type) : 값에 의한 전달 pass-by-value
-
객체타입의 데이터타입 (Object type, Reference type) : 참조에 의한 전달 pass-by-reference
객체란 데이터와 그 데이터에 관련한 동작(절차, 방법, 기능)을 모두 포함할 수 있는 개념적 존재. 이름과 값을 가지는 데이터를 의미하는 프로퍼티(property)와 동작을 의미하는 메소드(method)를 포함할 수 있는 독립적 주체이다
Boolean
-
new Boolean() 으로 Boolean객체 생성 가능하지만, 이 방법은 잘 쓰지 않는다.
ex) 값이 false 인 Boolean 객체를 포함한 어떤 객체는, true 값을 가짐
var myFalse = new Boolean(false); // 초기값 Boolean{false} var g = Boolean(myFalse); // 초기값 true
null & undefined
- 두 가지 모두 ‘없다’라는 표현이지만, undefined는 정의되지않음 이라는 js 엔진 내부적으로 초기화동작을 해주는 ‘없다’ 표현이고, null 은 개발자가 의도적으로(=명시적으로) 값이 없음을 표현하고 싶을 때 쓰는 ‘없다’ 표현
Numbers
11-03
String
-
문자열은 유사배열이다.
'6'.repeat(3); // 혜진예상: 666 // console: 666 'hi ken'.includes(' ke'); // 혜진예상: true / console: true 'what are you doing?'.startsWith('what '); // 혜진예상: true / console: 'I am doing FiNe'.endsWith('iNe'); // 혜진예상: true / console: ❎ 'Are you sure?'.indexOf(' yo'); // 혜진예상: 1 / console: 3 ❎ 'Yeah I am sure'.slice(2, 5); // 혜진예상: YeIh am sure' / console: 'ah ' ❎ 'I?doubt?that'.split('?'); // 혜진예상: Idoubtthat / console: (3) ['I', 'doubt', 'that'] ❎ 'Why would you doubt my word?'.split(''); // 혜진예상: Whywouldyoudoubtmyword? / console: (28) ['W', 'h', 'y', ' ', 'w', 'o', 'u', 'l', 'd', ' ', 'y', 'o', 'u', ' ', 'd', 'o', 'u', 'b', 't', ' ', 'm', 'y', ' ', 'w', 'o', 'r', 'd', '?'] 'You hAve BeEn DiSHonest'.toLowerCase(); // 혜진예상: you have been dishonest 'No wAy!'.toUpperCase(); // 혜진예상: NO WAY!문자열메서드
-
indexOf()
Returns the position of the first found occurrence of a specified value in a string
-
slice(begin, end);
Extracts a part of a string and returns a new string
-
split()
Splits a string into an array of substrings
-