0% found this document useful (0 votes)
8 views5 pages

JavaScript Basics: DOM, Async, Modules

JavaScript is a versatile programming language used for web development, capable of running in browsers and on servers. It allows for DOM manipulation, event handling, and asynchronous operations using Promises and async/await. Best practices include avoiding global variables, favoring const/let, and utilizing tools like linters and formatters.

Uploaded by

SRITHAR S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

JavaScript Basics: DOM, Async, Modules

JavaScript is a versatile programming language used for web development, capable of running in browsers and on servers. It allows for DOM manipulation, event handling, and asynchronous operations using Promises and async/await. Best practices include avoiding global variables, favoring const/let, and utilizing tools like linters and formatters.

Uploaded by

SRITHAR S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript — Page 1

Overview
JavaScript is the programming language of the web. It runs in browsers and on servers ([Link]). It
manipulates the DOM, handles events, and performs asynchronous operations.

Basic example:
[Link]('DOMContentLoaded', () => {
[Link]('Page ready');
});
JavaScript — Page 2
DOM manipulation & events
Select elements (querySelector, getElementById), attach event listeners, and update content.

const btn = [Link]('#myBtn');


[Link]('click', () => {
[Link]('#msg').textContent = 'Clicked!';
});
JavaScript — Page 3
Asynchronous JS: Promises & async/await
Fetch data using fetch API and async/await.

async function loadData() {


try {
const res = await fetch('/api/data');
const json = await [Link]();
[Link](json);
} catch (err) {
[Link](err);
}
}
JavaScript — Page 4
Modules & build tooling
Use ES modules: import/export. For production, bundlers (esbuild, webpack, rollup) or native modules
modern servers.

Example:
export function sum(a,b){ return a+b; }
import { sum } from './[Link]';
JavaScript — Page 5
Best practices
- Avoid global variables
- Favor const/let over var
- Handle errors and edge cases
- Keep functions small and testable
- Use linters (ESLint) and formatters (Prettier)

You might also like