JavaScript Examples
Modern, versatile, and powerful - the language that powers the web.
Example 1: Adding two Numbers
Code
// Taking input from user
let a = prompt("Enter first number:");
let b = prompt("Enter second number:");
// Calculating sum
let sum = Number(a) + Number(b);
// Displaying output
console.log("Sum is: " + sum);
Input
Enter first number: 10 Enter second number: 8
Output
Sum is: 18
Code Explanation
input() reads input as a string, int() converts it to an integer. a + b performs addition. console.log() prints the result.