Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/fs/package.module.fs.php on line 258

Warning: preg_match(): Compilation failed: invalid range in character class at offset 31 in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/router/package.module.router.php on line 465

Warning: preg_match(): Compilation failed: invalid range in character class at offset 30 in /home/niteshcpanel2/public_html/wp-content/plugins/nextgen-gallery/products/photocrati_nextgen/modules/router/package.module.router.php on line 465
Function returns function in Javascript | Nitesh Thapa

Function returns function in Javascript

We will see how function return function.We can call this function in two way but the second one is better.

script.js
function interviewQuestion(job){
	if(job == 'designer'){
		return function(name){
			console.log(name + 'can you please explain what UI design is?');
		}
	}
	else if(job == 'teacher'){
		return function(name){
			console.log('What subject do you teach,' + name + '?');
		}
	}
	else{
		return function(name){
			console.log('Hello ' + name +'What do you do?');
		}
	}
}
var teacherQuestion = interviewQuestion('teacher');
	teacherQuestion('John')
Alternative way
	interviewQuestion('designer')('Mark');

This code is using closure
function interviewQuestion(job){
			return function(name){
				if(job == 'designer'){
				console.log(name + 'can you please explain what UI design is?');
		}
			else if(job == 'teacher'){
				console.log('What subject do you teach,' + name + '?');
			}
			else{
			console.log('Hello ' + name +'What do you do?');
			}
			}
		 }
		 interviewQuestion('designer')('Mark')

Notice: compact(): Undefined variable: limits in /home/niteshcpanel2/public_html/wp-includes/class-wp-comment-query.php on line 821

Notice: compact(): Undefined variable: groupby in /home/niteshcpanel2/public_html/wp-includes/class-wp-comment-query.php on line 821

Warning: count(): Parameter must be an array or an object that implements Countable in /home/niteshcpanel2/public_html/wp-includes/class-wp-comment-query.php on line 399

Leave a Reply

Your email address will not be published. Required fields are marked *