2.5 Data types

히진로그·2022년 1월 24일
0

Modern-Javascript

목록 보기
2/14

출처: https://javascript.info/

  • 혼자 읽고 타이핑하며 이해하면서 공부한 흔적 남기기

A value in JavaScript is always of a certain type.

자바스크립트의 값은 항상 특정한 타입이다.

We can put any type in a variable.

let message = 'Hello';
message = 123456;

Programming languages that allow such things, such as JavaScript, are called 'dynamically typed', meaning that there exist data types, but variables are not bound to any of them.

자바스크립트는 동적 타입이라고 불린다.

데이터 유형이 존재하지만, 변수는 그 어느 것에도 구속되지 않는다.

Number

The number type represents both integer and floating point numbers.

Besides regular numbers, there are so-called 'special numeric values' which also belong to this data type: Infinity, -Infinity and NaN.

NaN represent a computational error. It is result of an incorrect or an undefined mathematical operation.

If there's a NaN somewhere in a mathematical expression, it propagates to the whole result(there's only one exception to that: NaN ** 0 is 1).

String

A string in JavaScript must be surrounded by quotes.

In JavaScript, there are 3 types of quotes.

  1. Double quotes: "Hello".
  2. Single quotes: 'Hello'.
  3. Backticks: Hello.

Backticks are 'extended functionality' quotes. They allow us to embed variables and expressions into a string by wrapping them in ${}.

let name = 'John';

alert(`Hello, ${name}`);

Boolean(logical type)

The boolean type has only two values: true and false.

Boolean values also come as a result of comparisons.

Boolean값은 또한 비교의 결과로도 도출된다.

let isGreater = 4 > 1;
alert(isGreater); // true

The 'null' value

It's just a special value which represents 'nothing', 'empty' or 'value unknown'.

The 'undefined' value

The meaning of undefined is 'value is not assigned'.

Technically, it is possible to explicitly assign undefined to a variable.

Objects

Objects are used to store collections of data and more complex entities.

The typeof operator

A call to typeof x returns a string with the type name.

0개의 댓글