JavaScript Array Example

This JavaScript example focuses on array methods and console output. It runs in a browser worker, so it is useful for learning JS logic without a Node.js server.

JavaScript Compiler

Code Example

const scores = [78, 89, 95, 91];
const boosted = scores.map(score => score + 2);
const total = boosted.reduce((sum, score) => sum + score, 0);

console.log("Boosted scores:", boosted.join(", "));
console.log("Average:", (total / boosted.length).toFixed(2));

Expected Output

Boosted scores: 80, 91, 97, 93
Average: 90.25

Practice Steps

  1. Open the JavaScript compiler and paste the code.
  2. Run it once, then change the score values.
  3. Add another array method such as filter() and inspect the terminal output.
HOME LEARN COMMUNITY DASHBOARD