DEV Community

Cover image for 📘 JavaScript for Beginners (Basics)
Swapnil Meshram
Swapnil Meshram

Posted on • Edited on

📘 JavaScript for Beginners (Basics)

Presented by Swapnil Meshram within mentorship @devsyncin

🎓 Started learning JavaScript with the guidance of @devsyncin with focused on basics concepts such as javascript variables, loops, with simple hands-on practice.

📌 1. What is JavaScript?

JavaScript is a high-level, interpreted programming language used to create dynamic and interactive effects on websites.

🔹 Runs in the browser
🔹 Client-side scripting (can also be used on the server with Node.js)
🔹 Lightweight and versatile

📌 2. How to Add JavaScript

You can include JavaScript in three main ways:


<!-- Inline JavaScript -->

<button onclick="alert('Hello!')">Click Me</button>

Enter fullscreen mode Exit fullscreen mode

<!-- Internal JavaScript -->

<script>
  alert("Hello from internal JS!");
</script>

Enter fullscreen mode Exit fullscreen mode

<!-- External JavaScript -->

<script src="script.js"></script>

Enter fullscreen mode Exit fullscreen mode

📌 3. Variables

Variables are containers for storing data.


var name = "John";      // old way
let age = 25;           // modern way
const country = "India"; // constant value

Enter fullscreen mode Exit fullscreen mode

📌 4. Data Types

JavaScript supports different data types:


String → "Hello"

Number → 123, 3.14

Boolean → true or false

Object → { key: value }

Array → [1, 2, 3]

Null → null

Undefined → undefined

Enter fullscreen mode Exit fullscreen mode

📌 5. Operators

Some basic operators:


+   // addition
-   // subtraction
*   // multiplication
/   // division
%   // modulus
==  // equal value
=== // equal value and type
!=  // not equal
>   // greater than
<   // less than

Enter fullscreen mode Exit fullscreen mode

📌 6. Conditional Statements

Used to perform different actions based on conditions.


let score = 90;

if (score >= 90) {
  console.log("Excellent");
} else if (score >= 70) {
  console.log("Good");
} else {
  console.log("Try again");
}

Enter fullscreen mode Exit fullscreen mode

📌 7. Loops

Loops run a block of code multiple times.


// for loop

for (let i = 0; i < 5; i++) {
  console.log(i);
}

Enter fullscreen mode Exit fullscreen mode

// while loop

let i = 0;
while (i < 5) {
  console.log(i);
  i++;

Enter fullscreen mode Exit fullscreen mode

✅ Summary

JavaScript allows you to:

Add interactivity (buttons, sliders)

Handle user input and events

Modify the webpage dynamically

Top comments (0)