JavaScript is a high-level, interpreted programming language that is commonly used to create interactive and dynamic web pages.
It is one of the core technologies of web development along with:
- HTML → Structure of the webpage
- CSS → Styling of the webpage
- JavaScript → Behaviour and Interactivity of the webpage
JavaScript is a versatile language that can be used for:
- Client-side development
- Server-side development
- Form validation
- Event handling
- DOM manipulation
- Animations
- AJAX communication
- Building modern web applications
- JavaScript is a high-level interpreted programming language.
- It supports object-oriented programming.
- It supports functional programming.
- It supports event-driven programming.
- It is a lightweight scripting language.
- It is case-sensitive.
- It can be executed directly in the browser.
- It works together with HTML and CSS.
- It is used to validate user input before submitting forms.
- It is widely used in modern frameworks like React, Angular, and Vue.js.
- JavaScript was created by Brendan Eich in 1995 at Netscape Communications Corporation.
- It was developed in just 10 days.
- Initially, it was named Mocha.
- Later, it was renamed to LiveScript.
- Finally, it was renamed to JavaScript.
- In 1996, Netscape submitted JavaScript to ECMA for standardization.
- ECMA stands for European Computer Manufacturers Association.
- In 1997, JavaScript became an ECMA standard.
- ES6 (ECMAScript 2015) was introduced in 2015 with many new features.
JavaScript code can be written inside the <script> tag.
<script>
// JavaScript Code
</script>JavaScript can be written in three ways:
- Inside
<head></head> - Inside
<body></body> - In an external
.jsfile
.(Dot Operator) → Used to access properties and methods.
Example:
document.write("Hello");-
write()is a method of the document object. -
JavaScript is a Case Sensitive Language.
Example:
var name;
var Name;Both are different variables.
- Always run the HTML file, not the
.jsfile directly.
Because JavaScript is executed within an HTML document by the browser.
nameis an internal predefined property in JavaScript and browsers.
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript</title>
</head>
<body>
<h1>Welcome to HTML</h1>
<h2>Welcome to KodNest</h2>
<script>
document.write("Welcome to JavaScript");
</script>
</body>
</html>Welcome to HTML
Welcome to KodNest
Welcome to JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript</title>
<script>
document.write("Welcome to JavaScript");
</script>
</head>
<body>
<h1>Welcome to HTML</h1>
<h2>Welcome to KodNest</h2>
</body>
</html>- JavaScript code is written inside the
<head>section. - It executes when the page loads.
document.write()writes content directly to the webpage.
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript</title>
<script src="Demo1.js"></script>
</head>
<body>
<h1>Welcome to HTML</h1>
<h2>Welcome to KodNest</h2>
</body>
</html>document.write("Welcome to JavaScript");- Reusable code
- Easy maintenance
- Cleaner HTML code
- Better organization
- Used in real-world projects
- Prefer External JavaScript files.
- Place JavaScript before the closing
</body>tag. - Avoid excessive use of
document.write(). - Use DOM methods such as:
getElementById()
querySelector()
innerHTML
createElement()
appendChild()JavaScript is one of the most important programming languages for web development.
It helps developers:
- Create interactive webpages
- Validate forms
- Handle events
- Manipulate HTML elements
- Build dynamic web applications
- Develop modern front-end and back-end applications
JavaScript, along with HTML and CSS, forms the foundation of modern web development.