🧠JavaScript Syntax Overview
JavaScript syntax is the set of rules that define a correctly structured JavaScript program. Let’s go through the main components:
1. Variables
javascript
CopyEdit
let x = 5; const name = "Alice"; var age = 30;
✅ Explanation:
-
let: block-scoped variable (can be changed).
-
const: block-scoped, constant value (cannot be reassigned).
-
var: function-scoped (older way of declaring variables).
2. Data Types
javascript
CopyEdit
let number = 42; // Number let text = "Hello"; // String let isTrue = true; // Boolean let items = [1, 2, 3]; // Array let person = { name: "Tom" };// Object let nothing = null; // Null let notDefined; // Undefined
3. Operators
javascript
CopyEdit
let sum = 10 + 5; // Arithmetic let isEqual = 10 === 5; // Comparison let isTrue = true && false; // Logical
4. Conditional Statements
javascript
CopyEdit
if (x > 10) { console.log("x is big"); } else { console.log("x is small"); }
5. Loops
➤ for loop:
javascript
CopyEdit
for (let i = 0; i < 5; i++) { console.log(i); }
➤ while loop:
javascript
CopyEdit
let i = 0; while (i < 5) { console.log(i); i++; }
6. Functions
javascript
CopyEdit
function greet(name) { return "Hello " + name; } const result = greet("Alice"); // "Hello Alice"
...
show more
🧠JavaScript Syntax Overview
JavaScript syntax is the set of rules that define a correctly structured JavaScript program. Let’s go through the main components:
1. Variables
javascript
CopyEdit
let x = 5; const name = "Alice"; var age = 30;
✅ Explanation:
-
let: block-scoped variable (can be changed).
-
const: block-scoped, constant value (cannot be reassigned).
-
var: function-scoped (older way of declaring variables).
2. Data Types
javascript
CopyEdit
let number = 42; // Number let text = "Hello"; // String let isTrue = true; // Boolean let items = [1, 2, 3]; // Array let person = { name: "Tom" };// Object let nothing = null; // Null let notDefined; // Undefined
3. Operators
javascript
CopyEdit
let sum = 10 + 5; // Arithmetic let isEqual = 10 === 5; // Comparison let isTrue = true && false; // Logical
4. Conditional Statements
javascript
CopyEdit
if (x > 10) { console.log("x is big"); } else { console.log("x is small"); }
5. Loops
➤ for loop:
javascript
CopyEdit
for (let i = 0; i < 5; i++) { console.log(i); }
➤ while loop:
javascript
CopyEdit
let i = 0; while (i < 5) { console.log(i); i++; }
6. Functions
javascript
CopyEdit
function greet(name) { return "Hello " + name; } const result = greet("Alice"); // "Hello Alice"
Or using arrow function:
javascript
CopyEdit
const greet = (name) => "Hello " + name;
7. Objects
javascript
CopyEdit
const user = { name: "John", age: 25, greet: function () { console.log("Hi!"); }, }; user.greet(); // "Hi!"
8. Arrays
javascript
CopyEdit
const fruits = ["apple", "banana", "cherry"]; console.log(fruits[1]); // "banana" fruits.push("orange"); // Add item
9. Events (in browser)
javascript
CopyEdit
document.getElementById("btn").addEventListener("click", () => { alert("Button clicked!"); });
10. Classes
javascript
CopyEdit
class Animal { constructor(name) { this.name = name; } speak() { console.log(this.name + " makes a sound."); } } const dog = new Animal("Dog"); dog.speak(); // "Dog makes a sound."
11. Promises & Async/Await
javascript
CopyEdit
function fetchData() { return new Promise((resolve, reject) => { setTimeout(() => resolve("Data loaded"), 1000); }); } async function loadData() { const result = await fetchData(); console.log(result); } loadData(); // After 1 second: "Data loaded"
✅ Summary:
ConceptUselet, constDeclare variablesFunctionsReuse blocks of codeObjects/ArraysStore collections of dataLoops/ConditionalsControl logic flowClassesCreate object blueprints (OOP)EventsHandle user actions in the browserAsync/AwaitHandle asynchronous operations like API calls
References:
https://www.expatriates.com/cls/59398924.html?1745218705
http://molbiol.ru/forums/index.php?showtopic=2409216
https://gettr.com/post/p3k5v59c206
https://bbs.superbuy.com/forum.php?mod=viewthread&tid=690054&extra=
https://velog.io/@hanryarthur1/AZ-801-%EC%8B%9C%ED%97%98-%EB%AC%B8%EC%A0%9C%EA%B0%80-Windows-Server-%ED%95%98%EC%9D%B4%EB%B8%8C%EB%A6%AC%EB%93%9C%EB%A5%BC-%EB%A7%88%EC%8A%A4%ED%84%B0%ED%95%98%EB%8A%94-%EB%8D%B0-%EC%96%B4%EB%96%BB%EA%B2%8C-%EB%8F%84%EC%9B%80%EC%9D%B4-%EB%90%A0%EA%B9%8C%EC%9A%94
show less