JavaScript Basic Tutorial



Introduction to JavaScript

JavaScript is a high-level, interpreted programming language primarily used for adding interactivity to web pages. It is supported by all modern web browsers and is widely used for front-end and back-end web development.

Hello World Example


console.log("Hello, World!");
  

Data Types

JavaScript provides several built-in data types, including:

  • Number: used to store numeric values
  • String: used to store text
  • Boolean: used to store boolean values (true or false)
  • Array: used to store a collection of elements
  • Object: used to store key-value pairs

Control Structures

JavaScript includes various control structures for decision-making and looping:

  • if statement: executes a block of code if a certain condition is true
  • for loop: iterates over a sequence of elements
  • while loop: repeats a block of code while a certain condition is true

Functions

In JavaScript, you can define functions to encapsulate reusable blocks of code:


function add(a, b) {
    return a + b;
}

var result = add(3, 5);
console.log("The result is: " + result);
  

Conclusion

This was a brief introduction to JavaScript and some of its basic concepts. JavaScript is a versatile language that powers interactivity on the web. Continue exploring to unlock its full potential!