Learning JavaScript Fundamentals: Execution Methods and Variables

Day 2 of Learning JavaScript 🚀 Today I explored some important JavaScript fundamentals: 🔸Ways to Execute JavaScript: 1️⃣ Inline JavaScript ▫️Written directly inside HTML attributes. Example: onclick="alert('Button clicked')". 2️⃣ Internal JavaScript ▫️Written inside <script> tags within the HTML file. 3️⃣ External JavaScript ▫️Written in a separate .js file and Best practice for real-world applications. ▫️Improves code readability and maintenance. 4️⃣ JavaScript Runtime & Node.js ▫️JavaScript was originally limited to browsers and Browsers use engines like V8 (Chrome) to execute JS. ▫️Node.js allows JavaScript to run outside the browser and it is built using the V8 engine. 🔸Variables in JavaScript: ▫️Three ways to declare variables: ➡️ var ❌ (old, avoid using) ➡️ let ✅ (block-scoped, can't redeclare) ➡️ const ✅ (block-scoped, values that should never change) 📌 Best Practices: ▫️Use camelCase for variables. ▫️Use UPPER_SNAKE_CASE for constants. ▫️Prefer const by default, use let when value changes. 🔸When to Use ✔ const → API URLs, config values, mathematical constants, DOM references. ✔ let → counters, loop variables, form inputs, changing states. Thank you to Harshit T sir #JavaScript #WebDevelopment #NodeJS #Frontend

To view or add a comment, sign in

Explore content categories