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.
पिछले topic में पढ़ा कि JavaScript में Function कैसे define करते हैं , और कैसे call / invoke करते हैं , but वो simple functions थे जो सिर्फ static result generate / return करते थे , इस topic में हम Parameterized Function के बारे में पड़ेंगे जिससे हम dynamic value return करा सकें।
Parameterized Function वो function होते हैं जो कि parameter accept करते हैं , इन functions को define करते समय हम parameter भी define करते हैं जो कि ensure करते हैं कि call करते समय हम कितने argument pass करने वाले हैं।
function में हम अपनी need के according कितने ही parameter pass कर सकते हैं। और यही parameter उस function के लिए as a variable work करते हैं।
function function_name(param1 , param2, param3...etc) { // your logic return value; //if mandatory }
? Technically देखा जाए तो किसी function के लिए Parameter और Argument दोनों अलग अलग हैं। Parameters function definition के समय define किये गए variables होते हैं , जबकि function call करते समय pass की गयी values / variables Arguments होते हैं।
File : js_param_function.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Parameterized Function In Hindi</title>
</head>
<body>
<script type="text/javascript">
function add(num1 , num2 , num3)
{
return num1+num2+num3;
}
document.write(`Addition Of 45, 67, 89 is : ${add(23,56,67,78,90)}`);
</script>
</body>
</html>
? Backticks (``) का use करके define की गयी string में हम ${ } ( dollar curly braces) के अंदर हम direct variables / expression को print करा सकते हैं।
हालाँकि ये जरूरी नहीं है कि , function call करते समय function में define किये गए सभी parameters की value pass की जाए। JavaScript हमें ये facility provide कराती है जिससे हम parameters की value default set कर सकते हैं।
Function call करते समय यदि value pass की गयी है तो passed value use होगी , otherwise default value use होगी।
function my_fun(param='default value') { //your logic }
File : js_param_function2.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Default Parameterized Function In Hindi</title>
</head>
<body>
<script type="text/javascript">
function param_fun(param = 'Default Value')
{
document.write(param);
}
param_fun(); /*call function without passing any value */
param_fun('Passed Value'); /*again call function with some value */
</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