![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – util.types.isGeneratorFunction() Method
The util.types.isGeneratorFunction() method checks whether the passed value is a generator function or not. If the above condition holds, it returns True, else False. The return value may differ from the original source code if a transpilation tool is used.
Syntax
util.types.isGeneratorFunction(value)
Parameters
- value − This input value takes input for the required parameter and checks if it's a Generator function or not.
It returns True or False based upon the input value passed.
Example 1
Create a file with the name "isGeneratorFunction.js" and copy the following code snippet. After creating the file, use the command "node isGeneratorFunction.js" to run this code.
// util.types.isGeneratorFunction() Demo Example // Importing the util module const util = require('util'); // Passing a normal function console.log("1." + util.types.isGeneratorFunction(function foo() {})); // Passing a generator function console.log("2." + util.types.isGeneratorFunction(function* gen() {}));
Output
C:\home
ode>> node isGeneratorFunction.js 1.true 2.false
Example 2
// util.types.isGeneratorFunction() Demo Example // Importing the util module const util = require('util'); var gen = function* id() { var index = 0; while (true) yield index++; } // Passing a generator function console.log("1." + util.types.isGeneratorFunction(gen)); var fn = function f() { console.log('Welcome to TutorialsPoint !') } // Passing a normal function console.log("2." + util.types.isGeneratorFunction(fn));
Output
C:\home
ode>> node isGeneratorFunction.js 1.true 2.false
Advertisements