100 Helloslanguages
Home / Languages / JavaScript

JavaScript

1995fraglet
webimperativefunctionalevent-driven.js.mjs.jsx
docker run --rm --platform="linux/amd64" 100hellos/javascript:latest

MCP + fragletc

MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →

This container runs a simple "Hello World!" program in JavaScript via Node.js.

Hello World

#!/usr/bin/env node

console.log("Hello World!")

Coding Guide

Language Version

Node.js 20.x

Execution Model

  • Interpreted, runs directly via Node.js
  • Code executes at the top level
  • Uses CommonJS module system by default
  • ES modules available with .mjs extension or "type": "module" in package.json

Key Characteristics

  • Dynamic typing
  • Case-sensitive
  • Semicolons optional (ASI - Automatic Semicolon Insertion)
  • Indentation is preserved from the injection point

Fragment Authoring

Write valid JavaScript statements or expressions. Your fragment becomes the script body. Code runs at the top level of the script.

Available Packages

Standard Node.js built-in modules are available:

  • fs - File system operations
  • path - Path manipulation
  • http - HTTP server/client
  • crypto - Cryptographic functionality
  • util - Utility functions
  • os - Operating system utilities
  • process - Process information and control

No additional npm packages are pre-installed. To use npm packages, you would need to install them (though this is typically not done in fraglet contexts).

Common Patterns

  • Print: console.log("message")
  • Variables: const x = 10; or let y = 20;
  • Functions: function name() {} or const name = () => {}
  • Arrays: [1, 2, 3]
  • Objects: { key: "value" }
  • Template literals: `Value: ${value}`
  • Arrow functions: const add = (a, b) => a + b

Examples

// Simple output
console.log("Hello, World!");

// Function definition
function greet(name) {
    return `Hello, ${name}!`;
}
console.log(greet("Alice"));

// Array processing
const numbers = [1, 2, 3, 4, 5];
const squared = numbers.map(x => x * x);
console.log(`Sum of squares: ${squared.reduce((a, b) => a + b, 0)}`);

// Object manipulation
const person = { name: "Bob", age: 30 };
console.log(`${person.name} is ${person.age} years old`);

Caveats

  • Fragments must be valid JavaScript that executes without errors
  • Variables are scoped to the script level
  • Use console.log() for output (not print())
  • Remember that Node.js is the runtime, not a browser environment (no DOM APIs)

Fraglet Scripts

Array Reduce

#!/usr/bin/env -S fragletc --vein=javascript
const numbers = [1, 2, 3, 4, 5];
const squared = numbers.map(x => x * x);
const sum = squared.reduce((a, b) => a + b, 0);
console.log(`Sum of squares: ${sum}`);

Echo Args

#!/usr/bin/env -S fragletc --vein=javascript
const args = process.argv.slice(2);
console.log("Args: " + args.join(" "));

Stdin Upper

#!/usr/bin/env -S fragletc --vein=javascript
const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf8");
console.log(input.trim().toUpperCase());

Test

#!/usr/bin/env -S fragletc --vein=javascript

console.log("Hello World!")

Connections

influenced by

Container Info

image100hellos/javascript:latest
build scheduleSunday
fragletenabled