The VikiD Truth

Knowledge base / Computing / JavaScript

Javascript | Javascript kata |Node JS | Data Types | Variables | Control Flow | Scope and Environment | Objects | Functions | Events | Prototypal Inheritance | Three.js | 3DE Code Editor |

Javascript

The plain idea

JavaScript is the programming language of the web. It began in 1995 as a small scripting language to make web pages interactive, and it has grown into one of the most widely used languages in the world: it runs in every browser, on servers (via Node.js), in desktop and mobile apps, and even on tiny devices. The language is formally called ECMAScript, and since the big ES6 (2015) update it has gained a modern yearly release (we are well past ES2015 now, with ES2024 shipped), adding features like let/const, arrow functions, classes, modules, promises and async/await.

Why it matters

If you want to build anything people use in a browser, you will meet JavaScript; there is effectively no alternative that runs natively everywhere the web does (WebAssembly complements it, it does not replace it). Learning it well, especially its genuinely unusual parts, closures, prototypes, the event loop, “the weird parts” my links below explore, unlocks front-end, back-end and full-stack development with a single language.

A worked example: the variable keywords in my notes

My notes above contrast var, let and const. The modern rule of thumb is simple: use const by default, let when you must reassign, and avoid var. Here is why var surprises people:

function demo() {
  if (true) { var x = 1; let y = 2; }
  console.log(x);   // 1  -- var leaked out of the block
  console.log(y);   // ReferenceError -- let stayed in the block
}

var is function-scoped and “hoisted” (usable before its line, which breeds bugs); let and const are block-scoped and must be declared before use. That single change, blocks that actually contain their variables, removed a whole category of classic JavaScript mistakes.

An everyday analogy

Think of a browser page as a stage. HTML is the set, CSS is the lighting and costumes, and JavaScript is the script the actors follow, deciding what happens when the audience (the user) claps, clicks or types. Without it the stage is a static tableau; with it the play comes alive.

Node JS "use strict"; Data Types Variables There are three ways of variable declaration:

  1. let - (block-scoped)
  2. const
  3. var - (function-scoped

“var” has no block scope. Variables, declared with var, are either function-scoped or global-scoped. “var” tolerates redeclarations If we declare the same variable with let twice in the same scope, that’s an error. “var” variables can be declared below their use. Declarations are hoisted, but assignments are not.

let message;

let message = 'Hello!';

let user = 'John', age = 25, message = 'Hello';

let user = 'John'
  , age = 25
  , message = 'Hello';

var message = 'Hello';

Control Flow Scope and Environment Objects Functions Prototypal Inheritance Events Three.js

Videos

Other

Last edited · 47 revisions

Tags: #Computing