JavaScript Syntaxes

Below are some common JavaScript syntaxes:


1. Variables and Constants:
```javascript
// Declaration and assignment of variables
let age = 25;
const pi = 3.14;

// String variables
let name = "John";
let message = 'Hello, world!';

// Numbers and mathematical operations
let num1 = 10;
let num2 = 5;
let sum = num1 + num2;
let product = num1 * num2;

// Booleans
let isTrue = true;
let isFalse = false;
```

2. Conditional Statements:
```javascript
let num = 10;

if (num > 0) {
  console.log("Positive number");
} else if (num < 0) {
  console.log("Negative number");
} else {
  console.log("Zero");
}
```

3. Loops:
```javascript
// For loop
for (let i = 0; i < 5; i++) {
  console.log("Iteration " + i);
}

// While loop
let count = 0;
while (count < 3) {
  console.log("Count is: " + count);
  count++;
}
```

4. Functions:
```javascript
// Function declaration
function greet(name) {
  return "Hello, " + name + "!";
}

let greeting = greet("Alice");
console.log(greeting); // Output: Hello, Alice!
```

5. Arrays:
```javascript
// Array declaration
let numbers = [1, 2, 3, 4, 5];

// Accessing elements in an array
let firstNumber = numbers[0];
console.log(firstNumber); // Output: 1

// Looping through an array
for (let i = 0; i < numbers.length; i++) {
  console.log(numbers[i]);
}

// Array methods
numbers.push(6); // Add an element to the end
numbers.pop(); // Remove the last element
numbers.unshift(0); // Add an element to the beginning
numbers.shift(); // Remove the first element
```

6. Objects:
```javascript
// Object declaration
let person = {
  name: "John",
  age: 30,
  city: "New York"
};

// Accessing object properties
console.log(person.name); // Output: John

// Modifying object properties
person.age = 31;

// Looping through object properties
for (let key in person) {
  console.log(key + ": " + person[key]);
}
```

7. Events and Event Listeners (in a browser environment):
```javascript
// Adding an event listener to a button with an ID "myButton"
const button = document.getElementById("myButton");
button.addEventListener("click", function() {
  console.log("Button clicked!");
});
```

Please note that these are just basic examples of JavaScript syntax. JavaScript is a versatile language used in web development, server-side development, and even in building desktop applications. The syntax can be combined and used in more complex ways to create powerful and interactive applications.


8. Classes and Object-Oriented Programming (ES6):
```javascript
// Class declaration
class Car {
  constructor(make, model, year) {
    this.make = make;
    this.model = model;
    this.year = year;
  }

  // Method within the class
  getInfo() {
    return this.make + " " + this.model + " (" + this.year + ")";
  }
}

// Creating objects from the class
let car1 = new Car("Toyota", "Camry", 2022);
let car2 = new Car("Honda", "Civic", 2023);

console.log(car1.getInfo()); // Output: Toyota Camry (2022)
console.log(car2.getInfo()); // Output: Honda Civic (2023)
```

9. Promises (Asynchronous Programming):
```javascript
// A function that returns a Promise
function fetchData() {
  return new Promise((resolve, reject) => {
    // Simulating an asynchronous task (e.g., API call or file reading)
    setTimeout(() => {
      const data = { name: "John", age: 30 };
      // Resolve the Promise with the data
      resolve(data);
      // Reject the Promise on error
      // reject(new Error("Failed to fetch data"));
    }, 2000); // Wait for 2 seconds
  });
}

// Using the Promise
fetchData()
  .then((data) => {
    console.log("Data fetched:", data);
  })
  .catch((error) => {
    console.error("Error:", error.message);
  });
```

10. Arrow Functions (ES6):
```javascript
// Regular function
function add(a, b) {
  return a + b;
}

// Arrow function with implicit return
const addArrow = (a, b) => a + b;

console.log(add(2, 3)); // Output: 5
console.log(addArrow(2, 3)); // Output: 5
```

11. Template Literals (ES6):
```javascript
let name = "Alice";
let age = 25;

// Using template literals
let message = `Hello, my name is ${name} and I am ${age} years old.`;
console.log(message); // Output: Hello, my name is Alice and I am 25 years old.
```

12. Destructuring Assignment (ES6):
```javascript
let person = {
  firstName: "John",
  lastName: "Doe",
  age: 30
};

// Destructuring assignment
let { firstName, lastName } = person;

console.log(firstName); // Output: John
console.log(lastName); // Output: Doe
```

These examples cover more advanced JavaScript features introduced in ES6 (ECMAScript 2015) and later versions. JavaScript is a constantly evolving language, and new features and improvements are introduced regularly, so it's essential to stay up-to-date with the latest developments in the language.


13. Spread and Rest Operators (ES6):
```javascript
// Spread Operator
let arr1 = [1, 2, 3];
let arr2 = [4, 5, 6];

let mergedArray = [...arr1, ...arr2];
console.log(mergedArray); // Output: [1, 2, 3, 4, 5, 6]

// Rest Operator
function sum(...numbers) {
  return numbers.reduce((acc, val) => acc + val, 0);
}

console.log(sum(1, 2, 3, 4, 5)); // Output: 15
```

14. Async/Await (ES2017):
```javascript
// Async function returning a Promise
function fetchData() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      const data = { name: "John", age: 30 };
      resolve(data);
    }, 2000);
  });
}

// Using async/await for asynchronous operations
async function getData() {
  try {
    const data = await fetchData();
    console.log("Data fetched:", data);
  } catch (error) {
    console.error("Error:", error.message);
  }
}

getData();
```

15. Modules (ES6):
```javascript
// File: math.js
export function add(a, b) {
  return a + b;
}

export function subtract(a, b) {
  return a - b;
}

// File: main.js
import { add, subtract } from './math.js';

console.log(add(5, 3)); // Output: 8
console.log(subtract(5, 3)); // Output: 2
```

16. Map and Set (ES6):
```javascript
// Map
let myMap = new Map();

myMap.set("name", "Alice");
myMap.set("age", 25);

console.log(myMap.get("name")); // Output: Alice
console.log(myMap.has("age")); // Output: true

// Set
let mySet = new Set();

mySet.add(1);
mySet.add(2);
mySet.add(3);
mySet.add(2); // Duplicates are ignored in a Set

console.log(mySet); // Output: Set { 1, 2, 3 }
```

17. Default Parameters (ES6):
```javascript
function greet(name = "Guest") {
  return "Hello, " + name + "!";
}

console.log(greet()); // Output: Hello, Guest!
console.log(greet("Alice")); // Output: Hello, Alice!
```

18. Symbol Data Type (ES6):
```javascript
// Symbol creation
const symbol1 = Symbol();
const symbol2 = Symbol("description");

console.log(typeof symbol1); // Output: symbol
console.log(symbol2.toString()); // Output: Symbol(description)
```

These are some additional JavaScript syntaxes and features that are commonly used in modern JavaScript development. Remember that JavaScript is a versatile language, and there are many more features and libraries available to cater to various programming needs. Regularly exploring and learning new features will help you become a more proficient JavaScript developer.


19. Closures:
```javascript
function outerFunction() {
  let outerVariable = "I am from the outer function.";

  function innerFunction() {
    console.log(outerVariable);
  }

  return innerFunction;
}

let innerFunc = outerFunction();
innerFunc(); // Output: I am from the outer function.
```

20. Callbacks:
```javascript
function doSomethingAsync(callback) {
  setTimeout(() => {
    console.log("Async operation complete!");
    callback();
  }, 2000);
}

function onComplete() {
  console.log("Callback function executed!");
}

doSomethingAsync(onComplete);
// Output after 2 seconds:
// Async operation complete!
// Callback function executed!
```

21. Prototypes and Prototypal Inheritance:
```javascript
// Constructor function
function Person(name, age) {
  this.name = name;
  this.age = age;
}

// Adding a method to the prototype
Person.prototype.sayHello = function() {
  console.log(`Hello, my name is ${this.name} and I am ${this.age} years old.`);
};

let person1 = new Person("Alice", 25);
let person2 = new Person("Bob", 30);

person1.sayHello(); // Output: Hello, my name is Alice and I am 25 years old.
person2.sayHello(); // Output: Hello, my name is Bob and I am 30 years old.
```

22. Promisifying Functions:
```javascript
function fetchDataFromAPI() {
  return new Promise((resolve, reject) => {
    // Some asynchronous API call
    setTimeout(() => {
      const data = { name: "John", age: 30 };
      resolve(data);
    }, 2000);
  });
}

// Promisifying the function
function fetchDataPromisified() {
  return new Promise((resolve, reject) => {
    fetchDataFromAPI()
      .then((data) => resolve(data))
      .catch((error) => reject(error));
  });
}

fetchDataPromisified()
  .then((data) => console.log("Data fetched:", data))
  .catch((error) => console.error("Error:", error.message));
```

23. Error Handling with Try...Catch:
```javascript
function divide(a, b) {
  if (b === 0) {
    throw new Error("Cannot divide by zero!");
  }
  return a / b;
}

try {
  let result = divide(10, 0);
  console.log("Result:", result);
} catch (error) {
  console.error("Error:", error.message);
}
// Output: Error: Cannot divide by zero!
```

These additional JavaScript concepts showcase the flexibility and power of the language. JavaScript is not only used for frontend web development but also extensively in backend development, mobile app development, and even for building desktop applications. Understanding these features will help you write more efficient and maintainable JavaScript code.


24. ES Modules (ES6):
ES modules provide a standard way to organize and share JavaScript code between different files, allowing for cleaner and more modular codebases.

// File: math.js
```javascript
export function add(a, b) {
  return a + b;
}

export function subtract(a, b) {
  return a - b;
}
```

// File: main.js
```javascript
import { add, subtract } from './math.js';

console.log(add(5, 3)); // Output: 8
console.log(subtract(5, 3)); // Output: 2
```

25. Array Methods:
JavaScript provides various built-in methods to manipulate arrays easily.

```javascript
let numbers = [1, 2, 3, 4, 5];

// forEach
numbers.forEach((num) => console.log(num)); // Output: 1, 2, 3, 4, 5

// map
let squaredNumbers = numbers.map((num) => num * num);
console.log(squaredNumbers); // Output: [1, 4, 9, 16, 25]

// filter
let evenNumbers = numbers.filter((num) => num % 2 === 0);
console.log(evenNumbers); // Output: [2, 4]

// reduce
let sum = numbers.reduce((acc, num) => acc + num, 0);
console.log(sum); // Output: 15
```

26. SetTimeout and SetInterval:
These functions allow you to schedule the execution of code after a specific time or at regular intervals.

```javascript
// SetTimeout
console.log("Start");
setTimeout(() => {
  console.log("This will be executed after 2 seconds.");
}, 2000);
console.log("End");

// SetInterval
let count = 1;
const intervalId = setInterval(() => {
  console.log("Interval: " + count);
  count++;
  if (count > 5) {
    clearInterval(intervalId);
  }
}, 1000);
```

27. JSON (JavaScript Object Notation):
JSON is a data interchange format that is easy to read and write for both humans and machines. It is often used to exchange data between a client and a server.

```javascript
let person = {
  name: "Alice",
  age: 25,
  hobbies: ["reading", "swimming", "painting"],
  address: {
    city: "New York",
    country: "USA"
  }
};

// Convert object to JSON string
let jsonString = JSON.stringify(person);
console.log(jsonString);
// Output: {"name":"Alice","age":25,"hobbies":["reading","swimming","painting"],"address":{"city":"New York","country":"USA"}}

// Parse JSON string back to an object
let parsedObject = JSON.parse(jsonString);
console.log(parsedObject.name); // Output: Alice
```

28. Fetch API (Client-Side HTTP Requests):
The Fetch API provides an easy way to make HTTP requests from the browser.

```javascript
fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));
```

These additional JavaScript concepts will help you become more proficient in working with JavaScript and building powerful web applications. JavaScript continues to evolve, and staying up-to-date with the latest features and best practices will allow you to write more efficient and modern code.


29. Arrow Functions and Lexical "this":
Arrow functions provide a concise syntax for writing functions and automatically capture the value of "this" from the surrounding context.

```javascript
// Regular function
function sayHello(name) {
  console.log("Hello, " + name + "!");
}

// Arrow function
const sayHi = (name) => {
  console.log("Hi, " + name + "!");
};

sayHello("Alice"); // Output: Hello, Alice!
sayHi("Bob"); // Output: Hi, Bob!
```

30. Object Destructuring:
Destructuring allows you to extract properties from objects and bind them to variables.

```javascript
const person = {
  firstName: "John",
  lastName: "Doe",
  age: 30
};

// Object destructuring
const { firstName, lastName } = person;
console.log(firstName); // Output: John
console.log(lastName); // Output: Doe
```

31. Array Destructuring:
Similar to object destructuring, array destructuring allows you to extract elements from arrays and assign them to variables.

```javascript
const numbers = [1, 2, 3, 4, 5];

// Array destructuring
const [first, second, ...rest] = numbers;
console.log(first); // Output: 1
console.log(second); // Output: 2
console.log(rest); // Output: [3, 4, 5]
```

32. Generators:
Generators are functions that can be paused and resumed, allowing for more efficient and readable asynchronous code.

```javascript
function* countDown(from) {
  while (from > 0) {
    yield from;
    from--;
  }
}

const countdownGenerator = countDown(5);

console.log(countdownGenerator.next().value); // Output: 5
console.log(countdownGenerator.next().value); // Output: 4
console.log(countdownGenerator.next().value); // Output: 3
console.log(countdownGenerator.next().value); // Output: 2
console.log(countdownGenerator.next().value); // Output: 1
console.log(countdownGenerator.next().value); // Output: undefined
```

33. Proxy:
The Proxy object allows you to create custom behavior for fundamental operations on an object.

```javascript
const person = {
  name: "Alice",
  age: 25
};

const personProxy = new Proxy(person, {
  get(target, prop) {
    console.log(`Getting ${prop}`);
    return target[prop];
  },
  set(target, prop, value) {
    console.log(`Setting ${prop} to ${value}`);
    target[prop] = value;
  }
});

console.log(personProxy.name); // Output: Getting name, Alice
personProxy.age = 30; // Output: Setting age to 30
```

34. BigInt:
The BigInt data type allows working with integers beyond the safe range of the Number data type.

```javascript
const bigNum = 123456789012345678901234567890n;
console.log(bigNum); // Output: 123456789012345678901234567890n
```

35. Nullish Coalescing Operator (??):
The nullish coalescing operator returns the right-hand side if the left-hand side is null or undefined; otherwise, it returns the left-hand side.

```javascript
const username = null;
const defaultName = "Guest";

const result = username ?? defaultName;
console.log(result); // Output: Guest
```

These advanced JavaScript concepts and syntax features can significantly enhance your ability to write clean, efficient, and modern JavaScript code. Continue to explore and experiment with these concepts to become a more proficient JavaScript developer. Remember, JavaScript is a versatile language, and there's always something new to learn and explore!


36. Optional Chaining (?.):
The optional chaining operator allows you to access nested properties or methods of an object without worrying about whether any intermediate property exists or not.

```javascript
const person = {
  name: "Alice",
  age: 30,
  address: {
    city: "New York",
    country: "USA"
  }
};

const cityName = person.address?.city;
console.log(cityName); // Output: "New York"

const zipCode = person.address?.zipCode;
console.log(zipCode); // Output: undefined (does not throw an error)
```

37. Nullish Coalescing Operator (??) vs. Default Assignment (||):
The nullish coalescing operator (??) and default assignment (||) behave differently when handling falsy values like empty strings, zero, null, and undefined.

```javascript
// Nullish Coalescing Operator (??)
const value1 = null ?? "default"; // Output: "default"
const value2 = "" ?? "default"; // Output: ""
const value3 = 0 ?? "default"; // Output: 0

// Default Assignment (||)
const value4 = null || "default"; // Output: "default"
const value5 = "" || "default"; // Output: "default"
const value6 = 0 || "default"; // Output: "default"
```

38. Async/Await with Error Handling:
When using async/await, you can handle errors using try...catch blocks.

```javascript
function fetchData() {
  return new Promise((resolve, reject) => {
    // Simulate an API call
    setTimeout(() => {
      const data = { name: "John", age: 30 };
      // Simulate an error
      // reject(new Error("Failed to fetch data"));
      resolve(data);
    }, 2000);
  });
}

async function getData() {
  try {
    const data = await fetchData();
    console.log("Data fetched:", data);
  } catch (error) {
    console.error("Error:", error.message);
  }
}

getData();
```

39. String Methods:
JavaScript provides numerous built-in methods for string manipulation.

```javascript
const message = "Hello, world!";

console.log(message.length); // Output: 13
console.log(message.toUpperCase()); // Output: "HELLO, WORLD!"
console.log(message.toLowerCase()); // Output: "hello, world!"
console.log(message.includes("world")); // Output: true
console.log(message.indexOf("world")); // Output: 7
console.log(message.slice(7, 12)); // Output: "world"
console.log(message.replace("world", "JavaScript")); // Output: "Hello, JavaScript!"
```

40. Array Spread and Rest Operators:
Spread and rest operators work with arrays similarly to how they work with objects.

```javascript
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];

const mergedArray = [...arr1, ...arr2];
console.log(mergedArray); // Output: [1, 2, 3, 4, 5, 6]

const [first, second, ...rest] = mergedArray;
console.log(first); // Output: 1
console.log(second); // Output: 2
console.log(rest); // Output: [3, 4, 5, 6]
```

These additional JavaScript concepts and syntax features will further expand your knowledge and capabilities as a JavaScript developer. Continue to explore and practice these concepts to become more proficient in writing clean, efficient, and modern JavaScript code. Happy coding!


41. RegExp (Regular Expressions):
Regular expressions are powerful patterns used to match and manipulate text.

```javascript
const pattern = /hello/gi;
const str = "Hello, hello, World!";

console.log(str.match(pattern)); // Output: ["Hello", "hello"]
console.log(str.replace(pattern, "Hi")); // Output: "Hi, Hi, World!"
console.log(pattern.test(str)); // Output: true
```

42. Array Methods: find() and findIndex():
The `find()` method returns the first element in an array that satisfies a given condition, while `findIndex()` returns the index of the first element that satisfies the condition.

```javascript
const numbers = [10, 20, 30, 40, 50];

const result = numbers.find((num) => num > 25);
console.log(result); // Output: 30

const index = numbers.findIndex((num) => num > 25);
console.log(index); // Output: 2
```

43. Object.freeze():
`Object.freeze()` prevents modifications to an object, making it immutable.

```javascript
const person = {
  name: "Alice",
  age: 30
};

Object.freeze(person);

// Attempt to modify the object (will have no effect)
person.age = 31;
console.log(person); // Output: { name: "Alice", age: 30 }
```

44. Promises.all():
`Promise.all()` accepts an array of promises and returns a new promise that fulfills when all promises in the array are resolved.

```javascript
function fetchData1() {
  return new Promise((resolve) => {
    setTimeout(() => resolve("Data 1"), 2000);
  });
}

function fetchData2() {
  return new Promise((resolve) => {
    setTimeout(() => resolve("Data 2"), 1500);
  });
}

Promise.all([fetchData1(), fetchData2()])
  .then((data) => console.log(data))
  .catch((error) => console.error(error));

// Output (after 2 seconds): ["Data 1", "Data 2"]
```

45. Global Object and "this":
In the browser, the global object is `window`, and in Node.js, it's `global`.

```javascript
console.log(this === window); // Output (in a browser): true
```

46. JSON.stringify() with Replacer Function:
You can use a replacer function in `JSON.stringify()` to control the serialization of specific properties.

```javascript
const person = {
  name: "Alice",
  age: 30,
  password: "secret"
};

const jsonString = JSON.stringify(person, (key, value) => {
  if (key === "password") {
    return undefined; // Remove password property from the JSON string
  }
  return value;
});

console.log(jsonString); // Output: "{"name":"Alice","age":30}"
```

47. Template Literal Tags:
You can use template literal tags to process template literals with a custom function.

```javascript
function tagFunction(strings, ...values) {
  return strings.reduce((acc, str, i) => {
    acc += str;
    if (values[i]) {
      acc += values[i].toUpperCase();
    }
    return acc;
  }, "");
}

const name = "Alice";
const age = 30;

const result = tagFunction`My name is ${name} and I am ${age} years old.`;
console.log(result); // Output: "My name is ALICE and I am 30 years old."
```

These are more JavaScript concepts and syntax features that will enrich your knowledge and proficiency as a JavaScript developer. Continuously learning and experimenting with these features will help you write cleaner, more efficient, and sophisticated JavaScript code for your projects. Happy coding!


48. Sets and WeakSets:
Sets are collections of unique values, and WeakSets are similar but allow only objects as values. The key difference is that WeakSets do not prevent garbage collection of the objects they hold references to.

```javascript
// Set
const set = new Set();
set.add(1);
set.add(2);
set.add(3);
set.add(2); // Duplicates are ignored in a Set

console.log(set); // Output: Set { 1, 2, 3 }
console.log(set.has(2)); // Output: true
console.log(set.size); // Output: 3

// WeakSet
const obj1 = { name: "Alice" };
const obj2 = { name: "Bob" };
const weakSet = new WeakSet([obj1, obj2]);

console.log(weakSet.has(obj1)); // Output: true
console.log(weakSet.has(obj2)); // Output: true
```

49. Maps and WeakMaps:
Maps are collections of key-value pairs, and WeakMaps are similar but only allow objects as keys and do not prevent garbage collection of the objects they hold references to.

```javascript
// Map
const map = new Map();
map.set("name", "Alice");
map.set("age", 30);

console.log(map.get("name")); // Output: Alice
console.log(map.has("age")); // Output: true

// WeakMap
const obj1 = { name: "Alice" };
const obj2 = { name: "Bob" };
const weakMap = new WeakMap([[obj1, 1], [obj2, 2]]);

console.log(weakMap.get(obj1)); // Output: 1
console.log(weakMap.get(obj2)); // Output: 2
```

50. Async Iteration (for-await-of):
You can use `for-await-of` to iterate over asynchronous data, such as promises or async generators.

```javascript
async function fetchData() {
  return new Promise((resolve) => {
    setTimeout(() => resolve("Data"), 2000);
  });
}

async function getData() {
  for await (const data of [fetchData(), fetchData(), fetchData()]) {
    console.log(data);
  }
}

getData();
// Output (after 2 seconds): "Data", "Data", "Data"
```

51. Dynamic Import (import()):
Dynamic import allows you to import modules dynamically at runtime.

```javascript
async function loadModule() {
  const module = await import('./module.js');
  module.doSomething();
}

loadModule();
```

52. Proxy Traps:
Proxy traps are used to intercept and customize object operations.

```javascript
const person = {
  name: "Alice",
  age: 30
};

const handler = {
  get(target, prop) {
    console.log(`Getting ${prop}`);
    return target[prop];
  },
  set(target, prop, value) {
    console.log(`Setting ${prop} to ${value}`);
    target[prop] = value;
  }
};

const personProxy = new Proxy(person, handler);

personProxy.age = 31;
console.log(personProxy.name); // Output: "Alice"
```

53. RegExp Lookahead and Lookbehind:
Lookahead and lookbehind assertions in regular expressions allow you to match patterns only if they are followed or preceded by specific patterns.

```javascript
const str = "apple, orange, banana";

const positiveLookahead = /(\w+)(?=,)/g;
console.log(str.match(positiveLookahead)); // Output: ["apple", "orange"]

const positiveLookbehind = /(?<=, )(\w+)/g;
console.log(str.match(positiveLookbehind)); // Output: ["orange", "banana"]
```

These additional JavaScript concepts and syntax features will further expand your understanding and capabilities as a JavaScript developer. By continuing to explore and practice these concepts, you'll be well-equipped to write efficient, modern, and advanced JavaScript code for a wide range of applications. Keep coding and learning!


54. BigInt and Number:
BigInt allows you to work with very large integers that are beyond the safe range of the Number data type.

```javascript
const largeNumber = 1234567890123456789012345678901234567890n;
console.log(largeNumber); // Output: 1234567890123456789012345678901234567890n

const normalNumber = 1234567890123456789012345678901234567890;
console.log(normalNumber); // Output: 1.2345678901234568e+39
```

55. String Padding:
You can use `String.prototype.padStart()` and `String.prototype.padEnd()` to add padding to strings.

```javascript
const num = 42;

console.log(num.toString().padStart(5, "0")); // Output: "00042"
console.log(num.toString().padEnd(5, "*")); // Output: "42***"
```

56. Promise.prototype.finally():
The `finally()` method allows you to specify a callback that will be executed, regardless of whether the promise is fulfilled or rejected.

```javascript
function fetchData() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      // Simulate an error
      // reject(new Error("Failed to fetch data"));
      resolve("Data fetched successfully.");
    }, 2000);
  });
}

fetchData()
  .then((data) => console.log(data))
  .catch((error) => console.error(error))
  .finally(() => console.log("Promise settled."));
```

57. Object.fromEntries():
The `Object.fromEntries()` method transforms a list of key-value pairs into an object.

```javascript
const entries = [
  ["name", "Alice"],
  ["age", 30]
];

const obj = Object.fromEntries(entries);
console.log(obj); // Output: { name: "Alice", age: 30 }
```

58. Error Object:
JavaScript provides built-in error objects that you can use for custom error handling.

```javascript
function divide(a, b) {
  if (b === 0) {
    throw new Error("Cannot divide by zero!");
  }
  return a / b;
}

try {
  let result = divide(10, 0);
  console.log("Result:", result);
} catch (error) {
  console.error("Error:", error.message);
}
// Output: Error: Cannot divide by zero!
```

59. IIFE (Immediately Invoked Function Expression):
IIFE is a function that is executed immediately after being created.

```javascript
(function () {
  console.log("IIFE executed!");
})();
// Output: IIFE executed!
```

60. Default Export and Named Export (ES6 Module):
In ES6 modules, you can use default exports and named exports to organize your code.

```javascript
// Default Export
export default function add(a, b) {
  return a + b;
}

// Named Export
export function subtract(a, b) {
  return a - b;
}
```

These additional JavaScript concepts and syntax features will further enhance your ability to write robust, modern JavaScript code. By familiarizing yourself with these concepts, you'll become a more skilled and versatile JavaScript developer. Keep exploring and practicing, and you'll be well-equipped to tackle a wide range of JavaScript projects!

  1. Entering the English page