Introduction to JavaScript

Get started with JavaScript — the versatile programming language powering dynamic web content and interactive websites worldwide.

Present State

JavaScript is a high-level, interpreted programming language primarily used for client-side web development. It allows you to create dynamic content, control multimedia, animate images, and build complex web applications. Originally developed for browsers, JavaScript now runs on servers, mobile devices, and desktop applications thanks to environments like Node.js.

Code Example

Here's a simple example that shows how to declare variables, create a function, and output text to the console:

Basic JavaScript Example

// 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:

  • Variable declaration using let and const
  • Function definition and invocation
  • String concatenation and console output

Description

JavaScript is an essential language for web development, enabling interactive features on websites. It is dynamically typed, supports event-driven programming, and integrates easily with HTML and CSS. Key features include:
  • Client-Side Execution: Runs in the user's browser for responsive user experiences.
  • Interpreted Language: No compilation needed — code runs directly.
  • Event Handling: Reacts to user inputs like clicks and keyboard events.
  • Extensive Ecosystem: Vast libraries and frameworks such as React, Angular, and Vue.js.
  • Server-Side Usage: With Node.js, JavaScript can power backend services and APIs.

Applications

  • Web Development: Creating interactive UI elements, form validation, animations.
  • Server-Side Programming: Using Node.js to build scalable web servers and APIs.
  • Mobile Apps: Frameworks like React Native enable mobile app development.
  • Game Development: Browser-based games leveraging Canvas and WebGL.
  • Desktop Applications: Electron allows building cross-platform desktop apps.

Multiple Choice Questions

Q1: What type of language is JavaScript?

  • A. Compiled
  • B. Interpreted
  • C. Assembly
  • D. Markup

Answer: B. Interpreted

Q2: Which environment allows running JavaScript outside the browser?

  • A. Node.js
  • B. React
  • C. Angular
  • D. Vue.js

Answer: A. Node.js

Q3: Which keyword declares a block-scoped variable?

  • A. var
  • B. let
  • C. const
  • D. function

Answer: B. let

Q4: What does console.log() do?

  • A. Alerts a message on screen
  • B. Outputs a message to the web console
  • C. Prompts the user for input
  • D. Declares a function

Answer: B. Outputs a message to the web console