If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.

JS ES8 Updates
ECMAScript 2017 (JavaScript ES8) ने JavaScript को और भी powerful और easy-तो-use बनाने के लिए कुछ bade updates introduce किये।
इस version के साथ JavaScript asynchronous programming को और better तरीके से handle कर सकती है, और कुछ new useful methods भी आये हैं।
Async/Await : Asynchronous Code लिखना अब Simple है।
Object.entries() और Object.values() : Object को iterate करने का easy तरीका।
String Padding : String को specific length तक pad करना।
Trailing Commas in Function Parameters Lists .
Conclusion
●●●
Asynchronous JavaScript handle करना कभी कभी difficult होता था, especially callbacks और Promises के साथ। ES8 ने async/await का support introduce किया, जो asynchronous code को लिखने और समझने में आसान बनाता है।
Async function एक ऐसा function होता है जो हमेशा promise return करता है। और await keyword का use करके हम किसी asynchronous operation का result easily wait कर सकते हैं बिना callback hell के।
async function fetchData() {
    try {
        let response = await fetch('https://api.example.com/data');
        let data = await response.json();
        console.log(data);
    } catch (error) {
        console.error('Error fetching data:', error);
    }
}await keyword asynchronous task का result आने तक wait करता है, और code को more synchronous बनाता है, इससे code को समझना और maintain करना easy हो जाता है।
●●●
JavaScript में पहले हम arrays के ऊपर iterate करने के लिए Object.keys() का use करते थे। लेकिन ES8 में Object.entries() और Object.values() methods आये जो objects के ऊपर iterate करना आसान बनाते हैं।
यह method एक object को key-value pairs में convert कर देता है, जिससे आप easily for...of loop या किसी और method से iterate कर सकते हैं।
const person = { name: 'John', age: 30, profession: 'Developer' };
for (let [key, value] of Object.entries(person)) {
    console.log(`${key}: ${value}`);
}
// Output:
// name: John
// age: 30
// profession: Developerइस method से आप object के सिर्फ values को access कर सकते हैं बिना keys के।
const person = { name: 'John', age: 30, profession: 'Developer' };
console.log(Object.values(person)); 
// Output: ['John', 30, 'Developer']●●●
ES8 में दो new methods आये padStart() और padEnd() जिनके through आप किसी string को specific length तक pad कर सकते हैं।
यह especially useful है जब आपको किसी specific length का output चाहिए, जैसे कि formatting के लिए।
For example
let str = '5';
console.log(str.padStart(4, '0')); // Output: '0005'
let str2 = 'Hi';
console.log(str2.padEnd(5, '!')); // Output: 'Hi!!!'padStart() string के start में pad करता है और padEnd() string के end में।
●●●
ES8 ने trailing commas का support भी introduce किया function parameter lists में।
इसका advantage ये होता है कि जब आप एक parameter को delete करते हैं या एक new parameter को add करते हैं, तो आपको commas के बारे में ज़्यादा सोचना नहीं पड़ता।
यह feature readability और maintainability को improve करता है।
function doSomething(
    param1,
    param2,
    param3, // Trailing comma
) {
    // Function body
}अगर आप एक और parameter add करते हैं तो आपको सिर्फ new parameter लिखना होता है बिना old line में changes किये।
●●●
JavaScript ES8 ने कुछ bade और काफी useful features introduce किये जो development को fast और आसान बनाते हैं।
Async/Await ने asynchronous code लिखना simple बनाया, और new methods जैसे Object.entries(), Object.values(), और string padding methods ने JavaScript को और भी powerful और flexible बनाया।
आपको ये blog पसंद आया होगा।
See you : )
Loading ...