All posts

JavaScript / Use any ASCII characters as a variable name

Posted On 02.04.2022

In JavaScript, you can use any ASCII characters as variable or function names, even non-English words or some special symbols:

const π = 3.1415
console.log(π);
 
const Δt = start_time - end_time;
console.log(Δt);
 
const tên_tui = "Huy";
console.log(tên_tui);
 
const 五 = 5;
console.log(五 + 10);
 
function 합계(первый, второй) {
    return первый + второй;
}
 
console.log(합계(7, 8));

But sadly you cannot use emojis:

const ⏰ = new Date();
//    ^^ Error: Invalid character

Apparently, this is not only possible in JavaScript but in almost every language.