JavaScript #4 ~ Data Types
Variables can store various types of data in their container. Before going into it any further, it is important to first address the categories within types of data. A single value can either be categorized as an object or a primitive value. For this post, I will only talk about primitive values and explain object values in a future post (as it is easier to follow-through that way 🙂).
7 Primitive Data Types
1) Number: Any number value that is shown as either a decimal or an integer.
let age = 23; let decimal = 1.01;
2) String: Sequence of characters used for text.
let firstName = 'John'; let lastName = 'Smith';
3) Boolean: Logical type that can only be true or false which is used for taking decisions.
let isTrue = true; let isFalse = false;
4) Undefined: a value taken by a variable that is not yet defined ('empty value').
let container;
5) Null: similar to undefined, null also means 'empty value', but done intentionally.
let container = null;
6) Symbol (ES2015): a value that is unique and cannot be changed.
7) BigInt (ES2020): larger integers than the Number type can hold.
Typeof
The typeof operator is used to determine the type of a particular data in string format. The typeof operator is useful because it is an easy way to check the type of a variable in a code. This is important because JavaScript is a is a dynamically typed language (more on this below). This means that you aren’t required to assign types to variables when you create them.
let word = 'hello' typeof word; // 'string' let num = '1'; typeof num; // 'number' let isTrue = true; typeof isTrue; // 'boolean'
More on Data Types
Although there are many types of data that can be used in JavaScript, developers only mostly use number, string, and boolean (sometimes undefined and null). However, I feel it is also useful to know the rest as well once I become more fluent in JavaScript.
One useful function of JavaScript is that it has dynamic typing. This means that I do not have to manually define the data type of the value stored in a variable. Instead, data types are determined automatically.
Author And Source
이 문제에 관하여(JavaScript #4 ~ Data Types), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@hjbaek91/2021.05.19W-TIL-Data-Types저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)