The reason for having semi-colons at the end of our statements is to signal the interpreter to stop parsing and begin to interpret/compile the code just read in. JS is a script so is compiled as each line is encountered.
Technically, when each statement is written on its own line, semi-colons are not needed since the parser knows where the statement ends and will stop at the end of the line. It’s when all the line-breaks are removed that problems surface. If one’s code is destined to be minified for production use, then forming the habit of always using semi-colons will ensure that process doesn’t corrupt the program.
코드가 프로덕션용으로 빌드될시 공백 라인이 지워짐에 따라 세미 콜른이 없으면 interpreter/compiler가 이해를 못할 리스크가 커서 오류가 날수 있다
There are 8 fundamental data types(구별법) in JavaScript:
// 아래 로그들을 보면 9007199254740991 + 2에서 잘못된 숫자 값이 반환 된다.
console.log(9007199254740991 + 1); // 9007199254740992
console.log(9007199254740991 + 2); // 9007199254740992
// n을 숫자 뒤에 붙여 BigInt를 사용한다.
console.log(9007199254740991n + 2n); // 9007199254740993n
// 혹은 BigInt() 합수를 사용한다 (new 키워드 없이)
const bigNumb = BigInt(9007199254740991)
const smallNumb = BigInt(2);
const answer = bigNumb + smallNumb;
console.log(answer); // 9007199254740993n
TIP: 참고로 다른 number 데이터 값들과 호환이 안된다. (다른 number와 연산작업 불가)
booleans: true or false (logical)
null: intentional absence of a value. 의도적으로 1)변수의 데이터 값이 없거나 2) unknown인 상태를 표현 하고 싶을때 사용하는 데이터 타입.
undefined: null과 비슷해 보일수 있으나 차이점이 있다.
1) typeof null === 'object' (js 언어 설계의 실수 였다고도 한다...)
2) typeof undefined === 'undefined'
3) undefined는 변수에 값이 할당이 안되었을때를 undefined 라고 한다.
Symbol: The symbol type is used to create unique identifiers for objects. Symbol은 주로 object에 유니크한 key값을 더해 다른 라이브러리나 프로그램에서 한 객체의 속성값을 overwrite 하는 상태를 방지 하기 위해 쓰인다. for...in loop이나 Object.key()를 통해 참조가 안된다. (encapsulation을 하기 위해서 쓰일지도... getter+setter 그리고 private field 대신에)
Object: collection of related data. 연관된 데이터들의 집합소 역활을 하는 '객체'.
First seven data types except object are primitive data types. - 처음 6개 데이터 타입은 원시값 primitive다.
Objects, including instances of data types, can have properties, stored information. The properties are denoted with a . after the name of the object, for example: 'Hello'.length.
Objects, including instances of data types, can have methods which perform actions. Methods are called by appending the object or instance with a period, the method name, and parentheses. For example: 'hello'.toUpperCase().
We can access properties and methods by using the ., dot operator.
Built-in objects, including Math, are collections of methods and properties that JavaScript provides.
Properties of an object can be either a value, or a method (a function only accessible to an instance of the object). A method is an attribute, but that does not make an attribute a method. A method is function, so performs some task. .length is a value, only.
String.prototype.trim() = method removes whitespace from both ends of a string and returns a new string, without modifying the original string
a = 42
Above we assign an integer value (a number) to the variable, a. When we poll(check the status of a measuring device, part of a computer, or a node in a network) the typeof a we are actually polling the type of 42. a is not an object, but a reference to an object. 42 is identified by the interpreter as being a number type so gives it a wrapper object of that type.
typeof 42 => 'number'
typeof a => 'number'
So a refers to an instance of a number type.
Instance of an object (or, perhaps more accurately phrased when talking about languages that have the notion, of a class) is an object that has been created and exists in memory. For example, when writing
var obj = new Foo();
Then a new instance of an object has been created (with new Foo).
Reference to an object is some kind of handle that allows us to access an instance. For example, in many languages (including JavaScript) obj now holds a reference to the instance we just created.
There can be many references to the same instance, as in
var obj2 = obj;
where now both obj and obj2 hold references to the same object.
instance는 생산자 혹은 constructor과 literal(문자) value를 통해 만들어져 메모리에 위치한 객체이며 변수(variable)은 메모리에 존재하는 데이터/객체를 접근해 주게 해준다.