๐TABLE OF CONTENTS
- What is JavaScript
- Setting up JavaScript
- Basic Syntax and Concepts
- Introduction to Control Flow
- Why JavaScript matters in Web Development
- Conclusion
๐๏ธ What is JavaScript?
JavaScript is a versatile programming language for the web. It enables developers to create interactive and dynamic webpages. Ever wondered how a button performs an action when clicked? Thatโs JavaScript at work!
From validating forms to building complete web applications, JavaScript is an essential tool for modern web development.
๐ ๏ธSetting up JavaScript
1. In the Browser: You can experiment with JavaScript directly in your browser's console. To open it:
- On Windows: Press
F12
orCtrl + Shift + J
- On Mac: Press
Command
+Option + J
Once open, type console.log("Hello, World!");
and press Enter to see your first JavaScript message.
2. In Code Editors: Developers typically write JavaScript in code editors like Visual Studio Code (VS Code). To get started:
- Install VS Code.
- Create a
.html
file and include your script usingscript
tags, or create a separate.js
file.
Example:
<script>
console.log("Hello from JavaScript!");
</script>
๐ Basic Syntax and Concepts
1. Variables and Constants
var
, let
, const
: These are used to store values.
-
let
is block-scoped and widely used. -
const
is for values that donโt change.
Example:
let username = "MJ";
const age = 26;
console.log(`Hello, ${username}! You are ${age} years old.`);
2. Data Types
JavaScript supports several data types:
- Primitive types: Numbers, Strings, Booleans, Null, Symbol, BigInt and Undefined.
- Complex types: Objects, Arrays. Example:
let isLearning = true; // Boolean
let tools = ["HTML", "CSS", "JavaScript"]; // Array
console.log(tools[0]); // Outputs: HTML
๐ Introduction to Control Flow
1. If/Else Statements
Use these to run code based on conditions.
Example:
let score = 85;
if (score >= 90) {
console.log("You got an A!");
} else if (score >= 70) {
console.log("You passed!");
} else {
console.log("Keep trying!");
}
2. Loops
Loops help you repeat actions:
- For Loop:
for (let i = 1; i <= 3; i++) {
console.log(`Iteration ${i}`);
}
- While Loop
let count = 0;
while (count < 3) {
console.log(`Count is ${count}`);
count++;
}
๐ Why JavaScript matters in Web development
JavaScript powers the web, enabling websites to respond to user actions without reloading.
- Enhances user experience with interactivity.
- Forms the basis of modern frameworks like React, Angular, and Vue.
- Used for building both the frontend and backend (e.g., with Node.js).
JavaScript isn't just limited to websites, it's used in mobile apps and game development.
๐ CONCLUSION
JavaScript is the language of the web, and mastering its basics sets the foundation for more advanced development. Take your time exploring these concepts and experimenting with your own code.
Next Steps: The next article will focus on JavaScript Functions, an essential building block for writing reusable and efficient code.
Until next time, your friendly neighborhood writer, MJ
Bye!!!!
Top comments (2)
You missed
Symbol
andBigInt
Thank you for pointing that out... I appreciate the feedback.