🏠 Home / Hub

⚡ JavaScript Lesson 01 — Variables & Data Types

← Back to JS Menu

1. Variable Declarations: var / let / const

// let — ပြောင်းနိုင်တဲ့ variable (recommended)
let name = "Ko Min"
let age = 25
let isStudent = true

// const — မပြောင်းနိုင်တဲ့ constant
const PI = 3.14159
const SITE_NAME = "My Website"

// var — old way (avoid using)
var oldVar = "I'm old"

// =============================
// let ကို ပြောင်းနိုင်:
let score = 0
score = 100       // ✅ OK

// const ကို မပြောင်းရ:
const MAX = 100
// MAX = 200     // ❌ Error!
မှတ်ချက်: ခုတော့ let + const ပဲ သုံးပါ — var ကို ရှောင်ပါ
↑ Button နှိပ်ပါ

2. Data Types

// String (text)
let str1 = "Hello"      // double quote
let str2 = 'World'      // single quote
let str3 = `Hi ${name}` // template literal

// Number
let int = 42
let float = 3.14
let neg = -10

// Boolean
let isTrue = true
let isFalse = false

// null — intentionally empty
let empty = null

// undefined — not assigned
let notSet
console.log(notSet)  // undefined

// Object
let person = { name: "Min", age: 25 }

// Array
let fruits = ["apple", "banana", "mango"]
"String" Text data
"Hello" / 'World' / `Template`
Number Numbers
42 / 3.14 / -10 / Infinity / NaN
Boolean True/False
true / false
null Intentionally empty
let x = null
Object Key-value pairs
{ name: "Min", age: 25 }

3. typeof — Type ကို စစ်ဆေး

typeof "hello"      // "string"
typeof 42           // "number"
typeof true         // "boolean"
typeof undefined    // "undefined"
typeof null         // "object" ← JS bug (historical)
typeof {}           // "object"
typeof []           // "object"
typeof function(){} // "function"

Value ထည့်ပြီး typeof ကြည့်ပါ:

4. String Operations

let first = "Ko"
let last = "Min"

// Concatenation
let full = first + " " + last         // "Ko Min"

// Template literal (better!)
let greeting = `Hello, ${first} ${last}!`  // "Hello, Ko Min!"

// String methods
"hello".length         // 5
"hello".toUpperCase()  // "HELLO"
"hello".includes("ell") // true
"hello world".split(" ") // ["hello", "world"]
"  hello  ".trim()      // "hello"
"hello".replace("l","r") // "herlo"
"hello".slice(1, 3)     // "el"

Template Literal try:

5. Number Operations

// Arithmetic
10 + 3   // 13
10 - 3   // 7
10 * 3   // 30
10 / 3   // 3.333...
10 % 3   // 1  (remainder/modulo)
2 ** 10  // 1024 (power)

// Math object
Math.round(3.7)   // 4
Math.floor(3.9)   // 3
Math.ceil(3.1)    // 4
Math.abs(-5)      // 5
Math.max(1,5,3)   // 5
Math.min(1,5,3)   // 1
Math.random()     // 0 to 1 random

// parseInt / parseFloat
parseInt("42px")    // 42
parseFloat("3.14")  // 3.14
Number("100")       // 100

6. Comparison & Type Coercion

// == loose equality (type convert)
5 == "5"    // true  ← dangerous!
0 == false  // true  ← dangerous!
null == undefined // true

// === strict equality (type check too)
5 === "5"   // false ← safer!
5 === 5     // true
0 === false // false

// ❌ Avoid ==, ✅ Use === always
OperatorMeaningExampleResult
===Strict equal5 === 5true
!==Strict not equal5 !== "5"true
>Greater than10 > 5true
<Less than3 < 5true
>=Greater or equal5 >= 5true
&&ANDtrue && falsefalse
||ORtrue || falsetrue
!NOT!truefalse

Next: JS Lesson 02 → Conditions →

📌 Study Checklist