Skip to content
youhoc
  • Pages
    • Home
    • Modern App Guidelines
    • Linux
      • Day 1: Linux Distributions & Navigation
      • Day 2: User Management
      • Day 3: File Permission & Ownership
      • Day 4: Package Management
      • Day 5: Services Management
    • Javascript
      • JS The Weird Part
        • Execution Context
        • icon picker
          Types & Operators
        • Objects & Functions
        • Error Handling & Strict Mode
        • Typescript, ES6, Tra
      • Modern JS
        • JS in the Browser
        • Data Storage JSON
        • Modern JS
        • Advanced Objects & Methods
        • Webpack & Babel
        • Async
      • jQuery
        • In-depth Analysis of jQuery
      • React-ready JS
        • Arrow Function
        • Template Literals
        • Logical AND, OR, Ternary, Nullish Operators
        • Destructuring & Rest Operator
        • Array Method
        • Immutability and Spread Operator
        • Promises, Async/Await, Callback
    • PHP
      • gruntJS
      • composer
      • MySQL
    • Docker
      • Container Basics
      • Container Networking
      • Container Image
      • Container Volume & Persistent Data
      • Dockerfile
      • Docker Compose
      • Docker Registry
    • Node.js
      • Installing & Exploring
      • Loading Modules
      • npm - Get Command Input
      • Web Server
        • Express Web Server
        • Template Engine & MVC
      • Authentication
      • 7. Databases
      • 8. Rest API
      • Errors
      • Sequelize
        • Sequelize Transactions: Đảm Bảo Tính Toàn Vẹn Dữ Liệu
        • 7 loại Data Types phổ biến Trong Sequelize
        • Phân Trang (Pagination) Trong Express.js Với Sequelize/MySQL
      • File Upload with Multer, Express.js
      • Hướng dẫn Cơ bản về Rest API
      • Server-Side Validation Với Express-Validator
      • Authentication Trong REST API Với JWT
      • Node-cron Simple to Complex Setup with PM2
      • HTMx Form: Gửi request, nhận response, và swap DOM
    • ReactJS
      • React from Andrew
        • Summary from Next
        • 1. Basics
        • 2. React Components
        • 3. Webpack
        • 4. Styling with SCSS
        • 5. React Router
        • 6. React Hook
      • Modern React From The Beginning
        • Intro to JSX
        • Vite Build Tools
        • Basic Component Creation
        • Component State
        • Props & Component Composition
        • useState with Inputs & Form Submission
        • useEffect, useRef & Local Storage
        • Async / Await and Http Request in React
        • React Router: Declarative Mode
        • ContextAPI
        • React Router: Framework Mode
          • File-routing & HTML Layouts
          • Server-side Data Query
          • Links & Navigation
          • Loaders
    • Typescript
      • Type User vs UserProp
    • Payload CMS
    • Authentication

Types & Operators

Types (loại biến trong JS) là “dynamic”, nghĩa là một biến đang lưu giá trị loại gì thì còn tùy code ở chỗ đó.
Primitive Types: data of a single value, NOT OBJECT
undefined: biến có tồn tại nhưng chưa được gán giá trị
null: biến có giá trị rỗng
boolean
number: floating point number (số thập phân)
string
symbol: used in ES6
img.jpg
Operators
Operator Precedence & Associativity
Các operator có thứ tự ưu tiên, nếu ngang cấp thì làm từ trái sang phải (hoặc phải sang trái)
Nhân chia thì cao hơn cộng trừ
trong ngoặc () cao hơn bên ngoài
Bảng thứ tự các operator theo cấp bậc
Coercion: chuyển đổi 1 biến từ loại này sang loại khác
var a = 1 + '2'; // 12
var a = 3 < 2 < 1; // false < 1, 0 < 1, true

// cẩn thận khi dùng equality
false == 0; // true
'3' == 3; // true
null == 0; // false
null < 1; // true, null = 0
'' == false; // true

// nên dùng strict equality, đừng so sánh
// so sánh các giá trị cùng loại
'3' === 3; // false
false === 0; // false
Operator Comparison Table
Existence and boolean
|| OR ít nhất một giá trị TRUE
OR cũng đồng thời return lại giá trị TRUE
falsse || true will return true
nếu 1 biến không tồn tại, sử dụng giá trị mặc định
&& AND tất cả đều phải TRUE
Convert một giá trị về 1 loại
Number()
Boolean()
Default Values
// nếu 1 biến không tồn tại, sử dụng giá trị mặc định
// nếu 1 biến có tồn tại, sử dụng giá trị hiện có
var name = name || ‘Your Name’;

// thay thế được IF statement

// OR có thứ tự precedence cao hơn EQUAL

Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.