Get started with JavaScript — the versatile programming language powering dynamic web content and interactive websites worldwide.
Here's a simple example that shows how to declare variables, create a function, and output text to the console:
// Declare variables
let greeting = "Hello, World!";
const year = 2025;
// Function to display greeting
function showGreeting() {
console.log(greeting + " Welcome to JavaScript in " + year);
}
// Call the function
showGreeting();
This example demonstrates:
let
and const
Q1: What type of language is JavaScript?
Answer: B. Interpreted
Q2: Which environment allows running JavaScript outside the browser?
Answer: A. Node.js
Q3: Which keyword declares a block-scoped variable?
Answer: B. let
Q4: What does console.log()
do?
Answer: B. Outputs a message to the web console