Introduction to JavaScript
What is JavaScript and why should you learn it?
JavaScript is a versatile programming language that runs in web browsers and on servers. It's the language that makes websites interactive and dynamic.
What is JavaScript?
JavaScript was created in 1995 by Brendan Eich at Netscape. Despite its name, it's not related to Java - the similar name was a marketing decision at the time.
Today, JavaScript is:
- The only language that runs natively in web browsers
- Used by 97% of all websites
- The foundation of frameworks like React, Vue, and Angular
- Used on servers with Node.js
- Used in mobile apps, desktop apps, and even IoT devices
Why Learn JavaScript?
1. It's Everywhere
JavaScript runs on every device with a web browser. No installation needed for users to run your code.
2. Easy to Start
You can start writing JavaScript right now. Open your browser's developer tools (F12) and start typing in the console!
console.log("Hello, World!");
3. High Demand
JavaScript developers are in high demand. It consistently ranks among the top programming languages for job opportunities.
Your First JavaScript Code
Let's write your first JavaScript program. Try this in the Edodo Pen:
<!DOCTYPE html>
<html>
<head>
<title>My First JavaScript</title>
</head>
<body>
<h1 id="greeting">Hello!</h1>
<script>
// Change the heading text
document.getElementById('greeting').textContent = 'Hello, JavaScript!';
// Log a message to the console
console.log('Script executed successfully!');
</script>
</body>
</html>
This code:
- Creates a heading with the text "Hello!"
- Uses JavaScript to change it to "Hello, JavaScript!"
- Logs a message to the browser's console
Summary
JavaScript is essential for web development and opens doors to many types of applications. In the next chapter, we'll learn about variables and data types.