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.
Anonymous Functions , जैसा कि नाम से ही ही मालूम होता है ऐसे functions जिनका कोई name नहीं है , JavaScript हमें ये facility provide करती है कि हम without name के functions भी define कर सके।
जैसे variable declare करते समय value को assign किया जाता है , ठीक वैसे ही function को भी assign कर सकते हैं।
let test = function(param1, param2) { //write your logic here }
Parameterized Functions की तरह ही इसमें हम parameters भी define कर सकते हैं।
File : js_anonymous_fun.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Anonymous Function In Hindi</title>
</head>
<body>
<script type="text/javascript">
let test = function()
{
document.write(`First Name : ${arguments[0]} <br> Last Name : ${arguments[1]}`);
}
/*we call the variable like a function */
test('Rahul', 'Rajput');
</script>
</body>
</html>
Anonymous function में भी normal function की तरह ही variable ( जो कि function के बाहर declared है ) को access कर सकते हैं , और variable number of arguments / length of arguments को भी आसानी से handle कर सकते हैं।
See Example
File : js_anonymous_fun2.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Anonymous Function In Hindi</title>
</head>
<body>
<script type="text/javascript">
let ex_var = 'A Variable';
let test = function()
{
document.write(`Full Name : ${arguments[0]} <br>`);
document.write(`External Variable : ${ex_var}`);
}
test('Rahul Rajput');
</script>
</body>
</html>
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook