본문으로 건너뛰기

Data Types

What are Data Types?

Data types refer to the type of data, such as characters, numbers, true/false, etc.


1. Number

The number type represents numerical values.

Example:

let age = 16;
let height = 170.5;

2. String

A string represents text information. It includes characters, words, or sentences enclosed within quotes (' ', " ").

Example:

let name = 'Jihoon';
let message = 'Hello?';

3. Boolean

The boolean data type can only hold one of two values: true or false, similar to turning a switch on or off.

Example:

let isStudent = true;
let hasDriverLicense = false;

4. Object

An object is a data type that encapsulates multiple pieces of data in one unit, much like a student's report card that includes the name, math score, English score, etc.

Example:

let student = {
name: 'Jihoon',
age: 16,
grade: 'Sophomore',
};

5. Array

An array lists data of the same type as shown below.

let fruits = ['apple', 'banana', 'grape'];

6. Other Data Types

  • null

null represents a special value that means 'no value'. It is used when you want to explicitly state that a variable is not assigned any value by intentionally assigning null.

Example:

let emptyValue = null;

  • undefined

undefined indicates that a variable has been declared but has not yet been assigned any value. It means that the value is not defined. If you declare a variable without initializing it, JavaScript automatically assigns the value undefined to it.

Example:

let notDefinedYet;
console.log(notDefinedYet); // Output: undefined
  • null and undefined both represent the concept of "no value," but they are used in different contexts with different meanings. null is used intentionally to express the absence of a value, while undefined indicates the state of a variable that has been declared but has not yet been assigned a value.

다음 내용이 궁금하다면?

월 12,500원 PLUS 멤버십 가입 or 강의를 등록해 주세요!