32. Generators Basics in Javascript. Creating Generator with simple example. ES6 | ES2015

preview_player
Показать описание
Hi Friends
In this video, we will see how to create generators in the javascript.

If you like this video, please subscribe to my channel
Рекомендации по теме
Комментарии
Автор

Good Afternoon sir
This is the defination i come accross on google for geneartors but ur explaination is kind of different from this

In JavaScript, generators are a special type of function that can be paused and resumed, allowing you to produce a sequence of values over time. This is achieved using the function* syntax to define the generator and the yield keyword to pause the execution and produce a value.

yashkant
Автор

Hello sir, in the below code why i am geting diff outputs for 2 examples eventhough both of them are sample().next() at the console statement.


function *sample1() {
console.log("hello");
console.log("hii");
yield "1st yield point";
console.log("execution after 1st yield");
yield "2nd yield point"
}

let a = sample1()
console.log(a.next());
console.log(a.next());




function *sample2() {
console.log("hello");
console.log("hii");
yield "1st yield point";
console.log("execution after 1st yield");
yield "2nd yield point"
}

let b = sample2().next();
console.log(b);
console.log(b);

Chakree
Автор

Hi Leela, what does the statement [symbol.iterator] : gen means? i mean what ES6 syntax it represents? or its just a particular way of calling a generator within a iterable object

vipinsharma-zxcb