Welcome to the exciting world of JavaScript! If you’re starting with web development, you’ve probably heard a lot about it. But what is it, and why should you learn it? This post should answer these questions and give you a foundation to start your journey.
What is JavaScript?
JavaScript is a programming language that adds interactivity to a web page or application. Once loaded, changing a web page’s content, style, and behaviour makes it dynamic and engaging for users.
Why Learn JavaScript?
- Widespread Usage: As one of the top programming languages globally, JavaScript enjoys immense popularity.
- Flexibility: It is used in both front-end and back-end development.
- Support Network: Has a large community of developers, limitless resources and tools.
- Career Prospects: Mastering JavaScript can unlock numerous career opportunities in the tech industry.
Displaying a Message in Browser Console
let message = "Welcome to JavaScript!";
console.log(message); // Outputs "Welcome to JavaScript!"
Basic Syntax
To get started, let’s look at some basic syntax.
// This is a comment in JavaScript
console.log("Hello, Dalvir!");
// Outputs "Hello, Dalvir!" to the console
Hello, Dalvir Example
When this code runs, it will update the HTML element with the ID ‘demo’ to display “Hello, Dalvir!”
document.getElementById("demo").innerHTML = "Hello, Dalvir!";
Changing Styles Example
This line of code changes the colour of the text inside the HTML element with the ID demo to pink.
document.getElementById("demo").style.color = "pink";
Adding Two Numbers Example
This line of code will add two numbers, helping answer the ultimate question of life.
let a = 39;
let b = 3;
let sum = a + b;
console.log(sum); // Outputs 42
JavaScript can be a powerful tool in web development. Learning it allows you to create more interactive and dynamic web pages. Understanding these basic concepts is the first step toward becoming a proficient JavaScript developer.
Just remember JavaScript is not only limited to creating simple interactions. Over the years it has evolved and it can support complex applications. You can build sophisticated user interfaces with frameworks like React, Angular, and Vue.js.
Additionally, like mentioned before it can be used in the back-end developtment. It can be used in server-side programming with Node.js, allowing you to create entire web applications using a single programming language.
In the next post, we’ll dive deeper into the basic concepts and syntax. Stay tuned!