JavaScript

coding learning websites codepractice

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

JavaScript Introduction


🔹 What is JavaScript?

JavaScript is a scripting language that allows you to create dynamic, interactive, and functional content on websites. It runs in the browser and enables you to handle:

  • Events

  • Validations

  • Dynamic content updates

  • Animations

  • API calls, and much more


🔹 Why Use JavaScript?

  • Adds interactivity to HTML pages

  • Responds to user actions (click, input, etc.)

  • Updates content without reloading the page

  • Validates user input before sending data to the server

  • Can communicate with servers using AJAX


🔹 JavaScript Syntax Example

<script>
  alert("Welcome to JavaScript!");
</script>

This pops up a message when the page loads.

 

🔹 Where Can JavaScript Be Placed?

1. Inside <script> tags in HTML
<script>
  document.getElementById("demo").innerHTML = "Hello!";
</script>
 
2. In the head or body of an HTML file
<head>
  <script>
    console.log("Page is loading...");
  </script>
</head>
 
3. External JavaScript file
<script src="script.js"></script>
 

And in script.js:

document.body.style.backgroundColor = "lightblue";
 

🔹 Output in JavaScript

Method Description
document.write() Writes directly to the HTML page
alert() Shows a popup box
console.log() Logs output to browser console
innerHTML Changes content of an element

🔹 JavaScript Variables

let x = 5;
const y = 10;
var name = "John";
 

Practice Questions

Q1. Show an alert message on page load.

Q2. Print a message in browser console.

Q3. Change the text of an HTML element.

Q4. Write content to the HTML page.

Q5. Change background color using JavaScript.

 

JavaScript

online coding class codepractice

JS Basics

JS Variables & Operators

JS Data Types & Conversion

JS Numbers & Math

JS Strings

JS Dates

JS Arrays

JS Control Flow

JS Loops & Iteration

JS Functions

JS Objects

JS Classes & Modules

JS Async Programming

JS Advanced

JS HTML DOM

JS BOM (Browser Object Model)

JS Web APIs

JS AJAX

JS JSON

JS Graphics & Charts

Go Back Top