본문 바로가기

Programming/JavaScript

Data Types (feat. 7 primitive data types)

There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null.

https://developer.mozilla.org/en-US/docs/Glossary/Primitive

 

Primitive - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods or properties. There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null.

developer.mozilla.org

 

Dynamic typing

Dynamically-typed languages are those (like JavaScript) where the interpreter assigns variables a type at runtime based on the variable's value at the time.

JavaScript has dynamic typing: We do not have to manually define the data type of the value stored in a variable. Instead, data types are determined automatically.

Value has type, NOT variable!

Symbol

Symbol is a built-in object whose constructor returns a symbol primitive — also called a Symbol value or just a Symbol — that's guaranteed to be unique. Symbols are often used to add unique property keys to an object that won't collide with keys any other code might add to the object, and which are hidden from any mechanisms other code will typically use to access the object. That enables a form of weak encapsulation, or a weak form of information hiding.

 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol

 

Symbol - JavaScript | MDN

Symbol is a built-in object whose constructor returns a symbol primitive — also called a Symbol value or just a Symbol — that's guaranteed to be unique. Symbols are often used to add unique property keys to an object that won't collide with keys any ot

developer.mozilla.org

BigInt

In JavaScript, BigInt is a numeric data type that can represent integers in the arbitrary precision format. In other programming languages different numeric types can exist, for examples: Integers, Floats, Doubles, or Bignums.

https://developer.mozilla.org/en-US/docs/Glossary/BigInt

 

BigInt - MDN Web Docs Glossary: Definitions of Web-related terms | MDN

In JavaScript, BigInt is a numeric data type that can represent integers in the arbitrary precision format. In other programming languages different numeric types can exist, for examples: Integers, Floats, Doubles, or Bignums.

developer.mozilla.org

 

Typeof

let javaScriptIsFun = true;
console.log(javaScriptIsFun);
// print true

console.log(typeof true);
// print boolean

 

Dynamic typing example

처음에 boolean 값을 지정했어도

나중에 string 값으로 변경할 수 있음

두번째 변경할 때는 let 안 적어도 됨

let javaScriptIsFun = true;
javaScriptIsFun = 'YES!';
console.log(typeof javaScriptIsFun);
// print string

 

let year;
console.log(year);
console.log(typeof year);
// print undefined

 

'Programming > JavaScript' 카테고리의 다른 글

Basic Operators  (0) 2022.07.10
let, const and var  (0) 2022.07.10
Values and Variables  (0) 2022.07.10
Linking a JavaScript File  (0) 2022.07.08
Hello World!  (0) 2022.07.07