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)