Introduction to JavaScript
Welcome to JavaScript! JavaScript is a versatile programming language that helps developers add interactive features to websites. It can be used for simple tasks like showing alerts to creating full-featured applications.
What is JavaScript?
JavaScript was created in 1995 and has since become the most widely-used programming language for web development. Along with HTML and CSS, JavaScript forms the "holy trinity" of the web, allowing you to create rich, interactive websites.
Why Use JavaScript?
- Interactive Content: JavaScript makes your pages interactive and responsive to user actions.
- Dynamic Updates: JavaScript allows you to change content dynamically without refreshing the page.
- Extensive Ecosystem: Libraries and frameworks like React, Angular, and Vue are built using JavaScript.
Example: Hello, World!
To start, let’s write a simple program that prints “Hello, World!” to the console.
<script>
console.log("Hello, World!");
</script>
Open your browser’s console to see the message. You can open the console by pressing F12 or Ctrl+Shift+J on most browsers.
Activity
Try It Yourself!
Add the following code to your HTML file to display "Hello, World!" in the console:
<!DOCTYPE html>
<html>
<head>
<title>Hello World Example</title>
</head>
<body>
<script>
console.log("Hello, World!");
</script>
</body>
</html>
Save the file and open it in a browser. Check the console to see the message!
Quiz
Quick Quiz
- What is JavaScript primarily used for?
- What are the three main components of the web?
- How can you open the console in your browser?
Answers: JavaScript adds interactivity; HTML, CSS, and JavaScript; F12 or Ctrl+Shift+J.