🔵 🔵 🔵


Primary

၊၊||၊|။

JavaScript Syntax ○|Definition|1st|20260107010714-00-⌔

JavaScript - Wikipedia#Syntax

Syntax

Variables in JavaScript can be defined using either the var,1 let2 or const3 keywords. Variables defined without keywords will be defined at the global scope.

Arrow functions were first introduced in 6th Edition – ECMAScript 2015. They shorten the syntax for writing functions in JavaScript. Arrow functions are anonymous, so a variable is needed to refer to them in order to invoke them after their creation, unless surrounded by parenthesis and executed immediately.

Here is an example of JavaScript syntax.

// Declares a function-scoped variable named `x`, and implicitly assigns the
// special value `undefined` to it. Variables without value are automatically
// set to undefined.
// var is generally considered bad practice and let and const are usually preferred.
var x;

// Variables can be manually set to `undefined` like so
let x2 = undefined;

// Declares a block-scoped variable named `y`, and implicitly sets it to
// `undefined`. The `let` keyword was introduced in ECMAScript 2015.
let y;

// Declares a block-scoped, un-reassignable variable named `z`, and sets it to
// a string literal. The `const` keyword was also introduced in ECMAScript 2015,
// and must be explicitly assigned to.

// The keyword `const` means constant, hence the variable cannot be reassigned
// as the value is `constant`.
const z = "this value cannot be reassigned!";

// Declares a global-scoped variable and assigns 3.  This is generally considered
// bad practice, and will not work if strict mode is on.
t = 3;

// Declares a variable named `myNumber`, and assigns a number literal (the value
// `2`) to it.
let myNumber = 2;

// Reassigns `myNumber`, setting it to a string literal (the value `"foo"`).
// JavaScript is a dynamically-typed language, so this is legal.
myNumber = "foo";

Note the comments in the examples above, all of which were preceded with two forward slashes.

More examples can be found at the Wikibooks page on JavaScript syntax examples.

Printed 2026-06-28.

(echo:: @ )

Footnotes

  1. “var – JavaScript”. The Mozilla Developer Network. Archived from the original on 23 December 2012. Retrieved 22 December 2012.

  2. “let”. MDN web docs. Mozilla. Archived from the original on 28 May 2019. Retrieved 27 June 2018.

  3. “const”. MDN web docs. Mozilla. Archived from the original on 28 June 2018. Retrieved 27 June 2018.

Link to original

Secondary

• • •