MDN self-hosted library · e01.org
Lexical grammar / notebook

Lexical grammar

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
function comment() {
  // This is a one line JavaScript comment
  console.log("Hello world!");
}
comment();
js
function comment() {
  /* This is a one line JavaScript comment */
  console.log("Hello world!");
}
comment();
js
function comment() {
  /* This comment spans multiple lines. Notice
     that we don't need to end the comment until we're done. */
  console.log("Hello world!");
}
comment();
js
function comment(x) {
  console.log("Hello " + x /* insert the value of x */ + " !");
}
comment("world");
js
function comment() {
  /* console.log("Hello world!"); */
}
comment();
js
#!/usr/bin/env node

console.log("Hello world");
js
const decl = 1; // Variable declaration (may also be `let` or `var`)
function fn() {} // Function declaration
const obj = { key: "value" }; // Object keys
// Class declaration
class C {
  #priv = "value"; // Private field
}
lbl: console.log(1); // Label