Quy tắc đặt tên áp dụng trong khi viết mã Javascript.
// Naming Rules in Javascript
// Variables
let fullName = "Lai Dinh Cuong";
// Boolean variables
let isStudent = false;
let hasMoney = false;
// Functions
function getInfo() {
return "ABC";
}
// Constants
const HEIGHT = 1720;
const BIRTH_DAY = 19900924;
// Classes
class SleepCalculator {
constructor(bedtime, wakeupTime) {
this.bedtime = bedtime;
this.wakeupTime = wakeupTime;
}
getInfo() {
return [
this.bedtime,
this.wakeupTime
]
}
}
let calculator = new SleepCalculator("21:45", "05:30");
console.log(calculator.getInfo());
// Private functions
class Cat {
constructor(name, color, numLegs) {
this.name = name;
this.color = color;
this.numLegs = numLegs;
this.detail = this._getName();
}
_getName() {
return this.name + ", legs: " + this.numLegs + ", color: " + this.color;
}
}
let cat = new Cat("Tom", "white", 4);
console.log(cat);