PLDB
Languages Features Calendar About Lists Add Language
GitHub icon

JavaScript

JavaScript

JavaScript is a programming language created in 1995 by Brendan Eich.

JavaScript (), often abbreviated as JS, is a high-level, dynamic, weakly typed, prototype-based, multi-paradigm, and interpreted programming language. Alongside HTML and CSS, JavaScript is one of the three core technologies of World Wide Web content production. It is used to make webpages interactive and provide online programs, including video games. Read more on Wikipedia...

Try now: Web · Riju · Replit

#2on PLDB 27Years Old 6.0mUsers

Example code from Riju:

console.log("Hello, world!");

Example code from hello-world:

console.log("Hello World");

Example code from the Hello World Collection:

// Hello world in JavaScript console.log("Hello World");

Example code from Linguist:

alert("dude!")

Example code from Wikipedia:

var minstake = 0.00000100; // valor base //----------------------------------------- var autorounds = 99; // n° de rolls //====================================================== // if (profit > profit_max) { // error_title = "Maximum profit exceeded"; // error_info = "Maximum profit: " + number_format(profit_max, devise_decimal); // error_value = "Maximum profit exceeded - Maximum profit: " + number_format(profit_max, devise_decimal); // error = true; // } // else if (amount > balance) { // error_title = "Bet amount"; // error_info = "Maximum bet: " + number_format(balance, devise_decimal); // error_value = "Bet amount - Maximum bet: " + number_format(balance, devise_decimal); // error = true; // } var handbrake = 1.0000000; // valor lose pause game var autoruns = 1; // else if (amount > bet_max) { // error_title = "Bet amount"; // error_info = "Maximum bet: " + number_format(bet_max, devise_decimal); // error_value = "Bet amount - Maximum bet: " + number_format(bet_max, devise_decimal); // error = true; // } // else if (amount < bet_min) { // error_title = "Bet amount"; // error_info = "Minimum bet: " + number_format(bet_min, devise_decimal); // error_value = "Bet amount - Minimum bet: " + number_format(bet_min, devise_decimal); // error = true; // } function playnow() { if (autoruns > autorounds ) { console.log('Limit reached'); return; } document.getElementById('double_your_btc_bet_hi_button').click(); setTimeout(checkresults, 1000); return;} function checkresults() { if (document.getElementById('double_your_btc_bet_hi_button').disabled === true) { setTimeout(checkresults, 1000); return; } var stake = document.getElementById('double_your_btc_stake').value * 1; var won = document.getElementById('double_your_btc_bet_win').innerHTML; if (won.match(/(\d+\.\d+)/) !== null) { won = won.match(/(\d+\.\d+)/)[0]; } else { won = false; } var lost = document.getElementById('double_your_btc_bet_lose').innerHTML; if (lost.match(/(\d+\.\d+)/) !== null) { lost = lost.match(/(\d+\.\d+)/)[0]; } else { lost = false; } if (won && !lost) { stake = minstake; console.log('Bet #' + autoruns + '/' + autorounds + ': Won ' + won + ' Stake: ' + stake.toFixed(8)); } if (lost && !won) { stake = lost * 2.1; console.log('Bet #' + autoruns + '/' + autorounds + ': Lost ' + lost + ' Stake: ' + stake.toFixed(8)); } if (!won && !lost) { console.log('Something went wrong'); return; } document.getElementById('double_your_btc_stake').value = stake.toFixed(8); autoruns++; if (stake >= handbrake) { document.getElementById('handbrakealert').play(); console.log('Handbrake triggered! Execute playnow() to override'); return; } setTimeout(playnow, 1000); return; }playnow()

Keywords in JavaScript

abstract arguments await boolean break byte case catch char class const continue debugger default delete do double else enum eval export extends false final finally float for function goto if implements import in instanceof int interface let long native new null package private protected public return short static super switch synchronized this throw throws transient true try typeof var void volatile while with yield

Language features

Feature Supported Example Token
Binary Literals
// 0[bB][01]+n?
Floats
// (\.[0-9]+|[0-9]+\.[0-9]*|[0-9]+)([eE][-+]?[0-9]+)?
Hexadecimals
// 0[xX][0-9a-fA-F]+n?
Octals
// 0[oO]?[0-7]+n?
Sets
set = new Set()
set.add("foo")
Function Composition
function o(f, g) {
   return function(x) {
       return f(g(x));
   }
}
Destructuring
const o = {p: 42, q: true};
const {p, q} = o;
Default Parameters Pattern
function multiply(a, b = 1) {
 return a * b;
}
Line Comments
// A comment
//
Increment and decrement operators
let i = 0
i++
i--
Methods
class Person {
 method1() {}
 method2() {}
}
Functions
function helloWorld() {console.log("hi")}
Case Sensitivity
While Loops
let times = 10
while (times) {times--}
console.log("done")
Ternary operators
let i = true ? 1 : 0
Switch Statements
var animal = "dog"
switch (animal) {
 case "dog": console.log("yay"); break;
 case "cat": console.log("oh"); break;
}
Strings
"hello world"
`
Letter-first Identifiers
Inheritance
class B {}
class A extends B {}
Print() Debugging
console.log("Hi")
console.log
References
Multiline Strings
const lines = `one
two`
Anonymous Functions
(() => console.log("hello world"))()
Infix Notation
const six = 2 + 2 + 2
Implicit Type Casting
console.log("hello " + 2)
Assignment
var name = "John"
=
Directives
"use strict";
"use asm";
Generators
function* fibonacci(limit) {
    let [prev, curr] = [0, 1];
    while (!limit || curr <= limit) {
        yield curr;
        [prev, curr] = [curr, prev + curr];
    }
}
// bounded by upper limit 10
for (let n of fibonacci(10)) {
    console.log(n);
}
// generator without an upper bound limit
for (let n of fibonacci()) {
    console.log(n);
    if (n > 10000) break;
}
// manually iterating
let fibGen = fibonacci();
console.log(fibGen.next().value); // 1
console.log(fibGen.next().value); // 1
console.log(fibGen.next().value); // 2
console.log(fibGen.next().value); // 3
console.log(fibGen.next().value); // 5
console.log(fibGen.next().value); // 8
// picks up from where you stopped
for (let n of fibGen) {
    console.log(n);
    if (n > 10000) break;
}
Garbage Collection
First-Class Functions
[2.0,1.1].map(Math.round)
Exceptions
try {
 undefinedFn()
} catch (err) {
 console.log(err)
}
Constants
const one = 1
Constructors
class Person {
 constructor(name) {
   this._name = name
 }
}
new Person("Jane")
Comments
Conditionals
if (true)
 console.log("hi!")
Classes
class Person {}
Method Chaining
"hello world".toString().substr(0, 1).length
Booleans true false
Magic Getters and Setters
// Can be implemented in ES6 using proxies:
"use strict";
if (typeof Proxy == "undefined") {
    throw new Error("This browser doesn't support Proxy");
}
let original = {
    "foo": "bar"
};
let proxy = new Proxy(original, {
    get(target, name, receiver) {
        let rv = Reflect.get(target, name, receiver);
        if (typeof rv === "string") {
            rv = rv.toUpperCase();
        }
        return rv;
      }
});
console.log(`original.foo = ${original.foo}`); // "original.foo = bar"
console.log(`proxy.foo = ${proxy.foo}`);       // "proxy.foo = BAR"
Dynamic Properties
class Person {}
const person = new Person()
person.age = 50
Source Maps
{
 version: 3,
 file: 'min.js',
 names: ['bar', 'baz', 'n'],
 sources: ['one.js', 'two.js'],
 sourceRoot: 'http://example.com/www/js/',
 mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
Bitwise Operators
var x = 5 & 1;
Single Dispatch
Polymorphism
"a" + "b"; 1 + 2
MultiLine Comments
/* A comment
*/
/* */
Merges Whitespace
Lists
const list = [1,2,3]
Integers
const result = 1
Supports Breakpoints
if (false)
  debugger
Partial Application
const addNumbers = (num1, num2) => num1 + num2
const add5 = num => addNumbers(10, num)
Map Functions
[1,2.1].map(Math.round)
Binary Operators
1 + 1
Async Await
async doSomething => await somethingElse()
Expressions
1 + 1
Regular Expression Syntax Sugar
console.log("Hello World".match(/\w/))
Statements
let x = 3;
File Imports
import { helloWorld } from "./helloWorld.js";
Operator Overloading ϴ
Case Insensitive Identifiers ϴ
Multiple Inheritance ϴ
Function Overloading ϴ
Macros ϴ
Processor Registers ϴ
Multiple Dispatch ϴ
Pointers ϴ
Semantic Indentation ϴ
Abstract Types ϴ
Access Modifiers ϴ

Trending JavaScript repos on GitHub

repo stars description
WebGL-Fluid-Simulation 6010 Play with fluids in your browser (works even on mobile)
tech-interview-handbook 33598 💯 Materials to help you rock your next coding interview
google-access-helper 3644 谷歌访问助手破解版
UnblockNeteaseMusic 5101 Revive unavailable songs for Netease Cloud Music
gridstudio 5643 Grid studio is a web-based spreadsheet application with full integration of the Python programming language.
dsa.js-data-structures-algorithms-javascript 4576 Data Structures and Algorithms explained and implemented in JavaScript
flv.js 15970 HTML5 FLV Player
outline 5553 "The fastest wiki and knowledge base for growing teams. Beautiful feature rich markdown compatible and open source."
the-super-tiny-compiler 14459 ⛄️ Possibly the smallest compiler ever
Blog 1043 【前端进阶】优质博文
fullPage.js 27942 fullPage plugin by Alvaro Trigo. Create full screen pages fast and simple
uni-app 12081 uni-app 是使用 Vue 语法开发小程序、H5、App的统一框架
webtorrent 20280 ⚡️ Streaming torrent client for the web
learnVue 7570 Vue.js 源码解析
date-fns 19569 ⏳ Modern JavaScript date utility library ⌛️
awesome-selfhosted 35277 This is a list of Free Software network services and web applications which can be hosted locally. Selfhosting is the process of locally hosting and managing applications instead of renting from SaaS providers.
dribbble2react 1143 Transform Dribbble designs to React-Native code & YouTube video tutorials
complete-javascript-course 2088 "Starter files final projects and FAQ for my Complete JavaScript course"
graphql-js 14679 A reference implementation of GraphQL for JavaScript
RSSHub 8818 🍰 万物皆可 RSS
Web 6166 前端入门和进阶学习笔记,超详细的Web前端学习图文教程。从零开始学前端,做一个Web全栈工程师。持续更新...
NeteaseCloudMusicApi 11486 网易云音乐 Node.js API service
uppy 20872 The next open source file uploader for web browsers 🐶
CyberChef 5890 "The Cyber Swiss Army Knife - a web app for encryption encoding compression and data analysis"
VvvebJs 1848 Drag and drop website builder javascript library.

Books about JavaScript on goodreads

title author year reviews ratings rating
Eloquent JavaScript: A Modern Introduction to Programming Marijn Haverbeke 2010 141 1721 4.12
Professional JavaScript for Web Developers Nicholas C. Zakas 2005 31 559 4.14

Article source

PLDB - Build the next great programming language. v5.0.0 - Acknowledgements · Email · GitHub