Introduction to JavaScript

JavaScript is a versatile, high-level programming language primarily used to create interactive effects within web browsers. It enables developers to build dynamic web pages, control multimedia, animate images, and much more.

It runs on the client side (in the browser), but can also run on the server side with environments like Node.js.

Illustration of Introduction to JavaScript
Illustration of Introduction to JavaScript

Where JavaScript Fits in Web Development

JavaScript works alongside HTML and CSS:

  • HTML: Structures the content on the web page.
  • CSS: Styles the visual presentation.
  • JavaScript: Adds interactivity and dynamic behavior.
Core Web Technologies Comparison
TechnologyRole
HTMLContent structure
CSSDesign & layout
JavaScriptDynamic behavior & logic

Basic JavaScript Syntax

JavaScript code consists of statements and expressions. Here's a simple example that outputs text to the browser console:

📌 Deep Dive: Console Output

JAVASCRIPT
console.log('Hello, JavaScript!');
Output
Hello, JavaScript!

💡 JavaScript Execution

JavaScript code is executed line by line by the browser's JavaScript engine when the page loads or when triggered by events.

Embedding JavaScript in HTML

You can add JavaScript directly inside HTML files using the <script> tag:

📌 Deep Dive: Inline Script Example

HTML
<script>
  alert('Welcome to JavaScript!');
</script>
Effect
A popup alert with the message "Welcome to JavaScript!"