Related Topics

what is Protocols in Hindi

What is a Program in Hindi

What is a Secure Connection in Hindi

Introduction to WWW in Hindi

What are Development Tools in Hindi

What is a Web Browser in Hindi

What is a Server in Hindi

What is a UNIX Web Server in Hindi

What is Logging Users in Hindi

What is Dynamic IP Web Design in Hindi

Web Site Design Principles in Hindi

Site Planning in Hindi

Website Navigation in Hindi

what is Web Systems Architecture in Hindi

Architecture of Web-Based Systems in Hindi

Client-Server Architecture in Hindi

What is Caching in Hindi

: Proxies in Hindi

What is an Index in Hindi

What is a Load Balancer in Hindi

What is a Queue in Hindi

Web Application Architecture in Hindi

JavaScript in Hindi

Client-Side Scripting in Hindi

Introduction to Simple JavaScript in Hindi

: JavaScript Variables in Hindi

What are Conditions in JavaScript in Hindi

What are Loops in JavaScript in Hindi

What is Repetition (Looping) in JavaScript? in Hindi

What is an Object in JavaScript in Hindi

JavaScript Own Objects in Hindi

DOM in Hindi

What is a Web Browser Environment in Hindi

Forms in JavaScript in Hindi

DHTML in Hindi

What are Events in DHTML in Hindi

Browser Control in JavaScript in Hindi

AJAX in Hindi

AJAX-based Web Application in Hindi

Alternatives to AJAX in Hindi

XML in Hindi

Uses of XML in Hindi

Simple XML in Hindi

XML Key Components in Hindi

What is DTD (Document Type Definition) in Hindi

What is XML Schema (XSD) in Hindi

XML with Application in Hindi

XSL in Hindi

XSLT in Hindi

Web Service in hindi

PHP in Hindi

Server-Side Scripting in Hindi

PHP Arrays in Hindi

PHP Functions in Hindi

PHP Forms in Hindi

Advanced PHP Databases in Hindi

Introduction to Basic Commands in PHP in Hindi

Server Connection in PHP in Hindi

Database Creation in PHP in Hindi

Understanding Database Selection in PHP in Hindi

PHPMyAdmin in Hindi

Database Bugs in Hindi

PHP Database Query in Hindi

Related Subjects

What is a Function in JavaScript in Hindi

RGPV University / DIPLOMA_CSE / Web Technology

What is a Function in JavaScript in Hindi

JavaScript में function एक ऐसा code block होता है जिसे आप बार-बार call कर सकते हैं। जब हम किसी कार्य को बार-बार करना चाहते हैं, तो उसे function में डालते हैं, ताकि बार-बार उसी code को न लिखना पड़े। function को define करने के बाद, हम उसे किसी भी जगह पर call करके उसका उपयोग कर सकते हैं।

Function Ki Definition

JavaScript में function को define करने के लिए function keyword का उपयोग किया जाता है। यह एक reusable block होता है जो एक specific task को perform करता है।

function greet() {
console.log("Hello, World!");
}

यह function "greet" नाम से define किया गया है, जो "Hello, World!" को console पर print करेगा। इस function को हर जगह call करके यही output मिलेगा।

Defining Functions in JavaScript in Hindi

JavaScript में function को define करने के लिए syntax बहुत आसान है। आप एक function keyword का उपयोग करके उसे define कर सकते हैं।

Function Definition Syntax

  • Function define करने के लिए function keyword का उपयोग करें।
  • Function name देना आवश्यक है ताकि आप उसे call कर सकें।
  • Function body को curly braces {} के अंदर लिखा जाता है।
function sum(a, b) {
return a + b;
}

यह function "sum" दो arguments (a और b) लेता है और उनका sum return करता है।

Function Parameters and Arguments in Hindi

JavaScript में function में parameters और arguments का उपयोग किया जाता है। Parameters वे variables होते हैं जो function define करते समय declare किए जाते हैं। Arguments वे values होती हैं जिन्हें function call करते समय function में भेजा जाता है।

Parameters and Arguments

  • Parameters: Function define करते समय function ke parentheses ke andar likhe jaate hain.
  • Arguments: Jab hum function ko call karte hain, to us function mein actual values pass ki jaati hain, jo arguments ke roop mein hoti hain.
function multiply(x, y) {
return x * y;
}
multiply(5, 3); // Arguments: 5 aur 3

यह function "multiply" दो arguments x और y को लेता है, और उनका multiplication return करता है। function call करते समय 5 और 3 arguments pass किए गए हैं।

Returning Values from Functions in JavaScript in Hindi

JavaScript में function से value return करने के लिए return keyword का उपयोग किया जाता है। return statement function ke execution ko stop karne ke liye bhi kaam karta hai, aur jo value return hoti hai, wo function ke call ke response ke roop mein milti hai।

Returning Values

  • Return Statement: Function ke andar jo bhi statement return hota hai, wo function ke call ka result hota hai.
  • Jab return statement execute hota hai, function ka execution band ho jata hai.
function divide(a, b) {
if (b === 0) {
return "Cannot divide by zero";
}
return a / b;
}
let result = divide(10, 2); // Output: 5

यह function "divide" दो numbers ko divide करता है, और अगर denominator 0 होता है, तो function "Cannot divide by zero" return करता है। otherwise, result return किया जाता है।

Function Scope in JavaScript in Hindi

JavaScript में function scope ka matlab hai ki variables jo function ke andar declare hote hain, wo function ke andar hi accessible hote hain. Outer code mein wo variable accessible nahi hota।

Function Scope Explanation

  • Local Scope: Function ke andar jo variables declare hote hain, wo sirf us function ke andar hi accessible hote hain.
  • Global Scope: Agar koi variable function ke bahar declare kiya gaya ho, to wo poore program mein accessible hota hai.
function showName() {
let name = "John"; // Local variable
console.log(name);
}
showName(); // "John" // console.log(name); // Error: name is not defined

यह function "showName" नामक variable को local scope में define करता है, जिसका इस्तेमाल function ke andar hi kiya ja sakta hai। Outside the function, यह variable accessible नहीं होता है।

FAQs

Function in JavaScript is a block of code that performs a specific task and can be reused. Functions help in writing clean and modular code, which can be called multiple times throughout the program.

To define a function in JavaScript, use the function keyword followed by the function name, parameters (optional), and the block of code inside curly braces. Example: function myFunction() {}

In JavaScript, function parameters are the variables defined in the function declaration. Arguments are the actual values passed to the function when it is called. Example: function add(x, y) { return x + y; } Here, x and y are parameters, and values like 5 and 3 are arguments passed when the function is called.

In JavaScript, you can return values from a function using the return keyword. It sends the result of the function back to where it was called. Example: function multiply(a, b) { return a * b; }

Function scope refers to the area in which a variable is accessible. Variables declared inside a function are only accessible within that function, and not outside. This is called local scope.

Yes, a function can return multiple values in JavaScript by using an array or an object to store multiple values. Example: function getDetails() { return [1, "John", "Doe"]; }

Please Give Us Feedback