From c5940793c0b0ec4682a83836afc2b508e4233049 Mon Sep 17 00:00:00 2001 From: rasoolkhan16 Date: Mon, 6 Sep 2021 16:33:09 +0530 Subject: [PATCH 01/43] Translate 1-if-else-required --- .../15-function-basics/1-if-else-required/solution.md | 3 ++- .../15-function-basics/1-if-else-required/task.md | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md b/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md index e41c80418..bb54ffb54 100644 --- a/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md +++ b/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md @@ -1 +1,2 @@ -No difference. \ No newline at end of file +No difference. +कोई फर्क नहीं। diff --git a/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md b/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md index 4f69a5c8c..c1d83124c 100644 --- a/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md +++ b/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md @@ -4,9 +4,13 @@ importance: 4 # Is "else" required? +# क्या "else" आवश्यक है? + The following function returns `true` if the parameter `age` is greater than `18`. +यदि `age` पैरामीटर `18` से अधिक है, तो निम्नलिखित फ़ंक्शन `true` लौटाता है। Otherwise it asks for a confirmation and returns its result: +अन्यथा, यह एक पुष्टिकरण मांगता है और अपना परिणाम देता है: ```js function checkAge(age) { @@ -22,6 +26,7 @@ function checkAge(age) { ``` Will the function work differently if `else` is removed? +यदि `else` हटा दिया जाता है तो क्या फ़ंक्शन अलग तरह से काम करेगा? ```js function checkAge(age) { @@ -36,3 +41,4 @@ function checkAge(age) { ``` Is there any difference in the behavior of these two variants? +क्या इन दोनों रूपों के व्यवहार में कोई अंतर है? From e2877f1df13ceae3727a009a4172c3b932e52661 Mon Sep 17 00:00:00 2001 From: rasoolkhan16 Date: Mon, 6 Sep 2021 17:16:26 +0530 Subject: [PATCH 02/43] Translate 2-rewrite-function-question0or --- .../2-rewrite-function-question-or/solution.md | 9 ++++++--- .../2-rewrite-function-question-or/task.md | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md index c8ee9618f..de7e5ce37 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md @@ -1,17 +1,20 @@ Using a question mark operator `'?'`: +प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?`: ```js function checkAge(age) { - return (age > 18) ? true : confirm('Did parents allow you?'); + return age > 18 ? true : confirm("Did parents allow you?"); } ``` Using OR `||` (the shortest variant): +OR ऑपरेटर का उपयोग करते हुए `||` (सबसे छोटा संस्करण) ```js function checkAge(age) { - return (age > 18) || confirm('Did parents allow you?'); + return age > 18 || confirm("Did parents allow you?"); } ``` -Note that the parentheses around `age > 18` are not required here. They exist for better readabilty. +Note that the parentheses around `age > 18` are not required here. They exist for better readabiltiy. +ध्यान दें कि यहां `age > 18` के आसपास के कोष्ठकों की आवश्यकता नहीं है। वे बेहतर पठनीयता के लिए मौजूद हैं। diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index 46da079c0..507d8d07e 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -1,26 +1,34 @@ -importance: 4 +importance: 2 --- # Rewrite the function using '?' or '||' +# '?' या '||' का उपयोग करके फ़ंक्शन को फिर से लिखें| + The following function returns `true` if the parameter `age` is greater than `18`. +यदि `age` पैरामीटर `18` से अधिक है, तो निम्नलिखित फ़ंक्शन `true` लौटाता है। Otherwise it asks for a confirmation and returns its result. +अन्यथा, यह एक पुष्टिकरण मांगता है और अपना परिणाम देता है: ```js function checkAge(age) { if (age > 18) { return true; } else { - return confirm('Did parents allow you?'); + return confirm("Did parents allow you?"); } } ``` Rewrite it, to perform the same, but without `if`, in a single line. +इसे फिर से लिखें, वही प्रदर्शन करने के लिए, लेकिन बिना `if` के, एक पंक्ति में। Make two variants of `checkAge`: +'checkAge' के दो प्रकार बनाएं: 1. Using a question mark operator `?` 2. Using OR `||` +3. प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?` +4. OR ऑपरेटर का उपयोग करते हुए `||` From 722a4e1818bc20d0c1261a87828dca4b29d3cacb Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:18:26 +0530 Subject: [PATCH 03/43] fix numbering --- .../15-function-basics/2-rewrite-function-question-or/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index 507d8d07e..0ff9fb2cb 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -30,5 +30,5 @@ Make two variants of `checkAge`: 1. Using a question mark operator `?` 2. Using OR `||` -3. प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?` -4. OR ऑपरेटर का उपयोग करते हुए `||` +1. प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?` +2. OR ऑपरेटर का उपयोग करते हुए `||` From 906f4e80d7611cb6484d3723d26c808b51c584dd Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:22:13 +0530 Subject: [PATCH 04/43] fix autochange done by IDE --- .../2-rewrite-function-question-or/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md index de7e5ce37..f73af505b 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md @@ -3,7 +3,7 @@ Using a question mark operator `'?'`: ```js function checkAge(age) { - return age > 18 ? true : confirm("Did parents allow you?"); + return (age > 18) ? true : confirm('Did parents allow you?'); } ``` @@ -12,7 +12,7 @@ OR ऑपरेटर का उपयोग करते हुए `||` (सब ```js function checkAge(age) { - return age > 18 || confirm("Did parents allow you?"); + return (age > 18) || confirm('Did parents allow you?'); } ``` From 0c4bd5efb20c93a5bfc755d95ee33269f76c46c6 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:27:49 +0530 Subject: [PATCH 05/43] fix changes made by IDE --- .../15-function-basics/2-rewrite-function-question-or/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index 0ff9fb2cb..bd204330c 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -1,4 +1,4 @@ -importance: 2 +importance: 4 --- @@ -17,7 +17,7 @@ function checkAge(age) { if (age > 18) { return true; } else { - return confirm("Did parents allow you?"); + return confirm('Did parents allow you?'); } } ``` From 1e5439efe10cf69110e9b14f114d5c028f342f50 Mon Sep 17 00:00:00 2001 From: rskhan167 Date: Mon, 6 Sep 2021 17:45:15 +0530 Subject: [PATCH 06/43] Translate 3-min --- .../15-function-basics/3-min/solution.md | 5 ++++- 1-js/02-first-steps/15-function-basics/3-min/task.md | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/solution.md b/1-js/02-first-steps/15-function-basics/3-min/solution.md index 2236d9203..f46c297bb 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/solution.md +++ b/1-js/02-first-steps/15-function-basics/3-min/solution.md @@ -1,4 +1,5 @@ A solution using `if`: +`if` का उपयोग करके एक हल: ```js function min(a, b) { @@ -11,6 +12,7 @@ function min(a, b) { ``` A solution with a question mark operator `'?'`: +प्रश्न चिह्न ऑपरेटर `'?'` के साथ एक हल: ```js function min(a, b) { @@ -18,4 +20,5 @@ function min(a, b) { } ``` -P.S. In the case of an equality `a == b` it does not matter what to return. \ No newline at end of file +P.S. In the case of an equality `a == b` it does not matter what to return. +नोट: समानता `a == b` के मामले में यह मायने नहीं रखता कि क्या लौटाया जाए। diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 50edd0d36..7e9f72961 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -4,13 +4,16 @@ importance: 1 # Function min(a, b) +# फंक्शन min(a, b) + Write a function `min(a,b)` which returns the least of two numbers `a` and `b`. +एक फ़ंक्शन लिखें `min(a,b)` जो कम से कम दो नंबर `a` और `b` लौटाता है। For instance: +उदाहरण के लिए: ```js -min(2, 5) == 2 -min(3, -1) == -1 -min(1, 1) == 1 +min(2, 5) == 2; +min(3, -1) == -1; +min(1, 1) == 1; ``` - From f0d15ad9052ba4f1dc975bbc1219e22ac1a7921a Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Mon, 6 Sep 2021 17:46:48 +0530 Subject: [PATCH 07/43] fix autochange by IDE --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 7e9f72961..b6910a40d 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -13,7 +13,7 @@ For instance: उदाहरण के लिए: ```js -min(2, 5) == 2; -min(3, -1) == -1; -min(1, 1) == 1; +min(2, 5) == 2 +min(3, -1) == -1 +min(1, 1) == 1 ``` From 952f4472e059682c9a51cb24401ecbf0cbbcc73a Mon Sep 17 00:00:00 2001 From: rskhan167 Date: Fri, 10 Sep 2021 00:35:47 +0530 Subject: [PATCH 08/43] Translate article --- .../15-function-basics/4-pow/task.md | 6 +- .../15-function-basics/article.md | 270 +++++++++--------- 2 files changed, 144 insertions(+), 132 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index f569320c7..26b090f09 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -4,7 +4,7 @@ importance: 4 # Function pow(x,n) -Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, multiplies `x` by itself `n` times and returns the result. +एक function लिखें `pow(x,n)` जो `x` को `n` के शक्ति में लौटाता है। या, दूसरे शब्दों में, `x` को अपने आप से `n` गुणा से गुणा करता है और परिणाम देता है। ```js pow(3, 2) = 3 * 3 = 9 @@ -12,8 +12,8 @@ pow(3, 3) = 3 * 3 * 3 = 27 pow(1, 100) = 1 * 1 * ...* 1 = 1 ``` -Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`. +एक वेब-पेज बनाएं जो `x` और `n` के लिए संकेत देता है, और फिर `pow(x,n)` का परिणाम दिखाता है। [demo] -P.S. In this task the function should support only natural values of `n`: integers up from `1`. +नोट: इस टास्क में function को केवल `n` के प्राकृतिक मान का समर्थन करना चाहिए: `1` से ऊपर के पूर्णांक। diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index b12d0b9e7..1c635dd49 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -1,26 +1,28 @@ # Functions -Quite often we need to perform a similar action in many places of the script. +अक्सर हमें स्क्रिप्ट के कई स्थानों पर इसी तरह की कार्रवाई करने की आवश्यकता होती है। -For example, we need to show a nice-looking message when a visitor logs in, logs out and maybe somewhere else. +उदाहरण के लिए, जब कोई परिदर्शक इन करता है, लॉग आउट करता है और शायद कहीं और एक अच्छा दिखने वाला संदेश दिखाना चाहता है। -Functions are the main "building blocks" of the program. They allow the code to be called many times without repetition. +Functions प्रोग्राम के मुख्य "बिल्डिंग ब्लॉक्स" हैं। वे बिना दोहराव के कोड को कई बार कॉल करने की अनुमति देते हैं। -We've already seen examples of built-in functions, like `alert(message)`, `prompt(message, default)` and `confirm(question)`. But we can create functions of our own as well. +हम पहले से ही बिल्ट-इन function के उदाहरण देख चुके हैं, जैसे `अलर्ट (संदेश)`, `प्रॉम्प्ट (संदेश, डिफ़ॉल्ट)` और `पुष्टि करें (प्रश्न)`। लेकिन हम अपने स्वयं के functions भी बना सकते हैं। ## Function Declaration -To create a function we can use a *function declaration*. +## Function घोषणा -It looks like this: +function बनाने के लिए हम एक _function declaration_ का उपयोग कर सकते हैं। + +यह इस तरह दिख रहा है: ```js function showMessage() { - alert( 'Hello everyone!' ); + alert("सभी को नमस्कार!"); } ``` -The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above) and finally the code of the function, also named "the function body", between curly braces. +`function` कीवर्ड पहले जाता है, फिर _name of the function_ जाता है, फिर कोष्ठक के बीच _parameters_ की एक सूची (उपरोक्त उदाहरण में खाली) और अंत में function का कोड, जिसे "the function body" भी कहा जाता है , घुंघराले ब्रेसिज़ के बीच। ```js function name(parameters) { @@ -28,13 +30,13 @@ function name(parameters) { } ``` -Our new function can be called by its name: `showMessage()`. +हमारे नए function को इसके नाम से बुलाया जा सकता है: `showMessage()`। -For instance: +उदाहरण के लिए: ```js run function showMessage() { - alert( 'Hello everyone!' ); + alert( 'सभी को नमस्कार!' ); } *!* @@ -43,103 +45,107 @@ showMessage(); */!* ``` -The call `showMessage()` executes the code of the function. Here we will see the message two times. +`showMessage()` कॉल करने से function के कोड को निष्पादित करता है। यहां हम संदेश को दो बार देखेंगे। -This example clearly demonstrates one of the main purposes of functions: to avoid code duplication. +यह उदाहरण स्पष्ट रूप से function के मुख्य उद्देश्यों में से एक को प्रदर्शित करता है: कोड आवृत्ति से बचने के लिए। -If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it. +यदि हमें कभी भी संदेश या उसके दिखाए जाने के तरीके को बदलने की आवश्यकता होती है, तो यह कोड को एक ही स्थान पर संशोधित करने के लिए पर्याप्त है: वह function जो इसे आउटपुट करता है। ## Local variables -A variable declared inside a function is only visible inside that function. +## लोकल variables + +किसी function के अंदर घोषित एक variable केवल उस function के अंदर ही दिखाई देता है। -For example: +उदाहरण के लिए: ```js run function showMessage() { *!* - let message = "Hello, I'm JavaScript!"; // local variable + let message = "हैलो, मैं जावास्क्रिप्ट हूँ!"; // local variable */!* alert( message ); } -showMessage(); // Hello, I'm JavaScript! +showMessage(); // हैलो, मैं जावास्क्रिप्ट हूँ! -alert( message ); // <-- Error! The variable is local to the function +alert( message ); // <-- Error! variable function के लिए स्थानीय है ``` ## Outer variables -A function can access an outer variable as well, for example: +## बाहरी variables + +एक function बाहरी variable को भी एक्सेस कर सकता है, उदाहरण के लिए: ```js run no-beautify let *!*userName*/!* = 'John'; function showMessage() { - let message = 'Hello, ' + *!*userName*/!*; + let message = 'नमस्ते, ' + *!*userName*/!*; alert(message); } -showMessage(); // Hello, John +showMessage(); // नमस्ते, John ``` -The function has full access to the outer variable. It can modify it as well. +function के पास बाहरी variable तक पूर्ण पहुंच है। यह इसे बदल भी कर सकता है। -For instance: +उदाहरण के लिए: ```js run let *!*userName*/!* = 'John'; function showMessage() { - *!*userName*/!* = "Bob"; // (1) changed the outer variable + *!*userName*/!* = "Bob"; // (1) बाहरी variable बदल दिया let message = 'Hello, ' + *!*userName*/!*; alert(message); } -alert( userName ); // *!*John*/!* before the function call +alert( userName ); // *!*John*/!* फ़ंक्शन कॉल से पहले showMessage(); -alert( userName ); // *!*Bob*/!*, the value was modified by the function +alert( userName ); // *!*Bob*/!*, मान function द्वारा संशोधित किया गया था ``` -The outer variable is only used if there's no local one. +बाहरी variable का उपयोग केवल तभी किया जाता है जब कोई लोकल न हो। -If a same-named variable is declared inside the function then it *shadows* the outer one. For instance, in the code below the function uses the local `userName`. The outer one is ignored: +यदि function के अंदर एक ही नामित variable घोषित किया गया है तो यह _shadows_ बाहरी है। उदाहरण के लिए, नीचे दिए गए कोड में function लोकल `userName` का उपयोग करता है। बाहरी को अनदेखा किया जाता है: ```js run let userName = 'John'; function showMessage() { *!* - let userName = "Bob"; // declare a local variable + let userName = "Bob"; // एक local variable घोषित करें */!* let message = 'Hello, ' + userName; // *!*Bob*/!* alert(message); } -// the function will create and use its own userName +// फ़ंक्शन अपना स्वयं का userName बनाएगा और उसका उपयोग करेगा showMessage(); -alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable +alert( userName ); // *!*John*/!*, अपरिवर्तित, function बाहरी variable का उपयोग नहीं करता है ``` ```smart header="Global variables" -Variables declared outside of any function, such as the outer `userName` in the code above, are called *global*. +किसी function के बाहर घोषित variables, जैसे उपरोक्त कोड में बाहरी `userName`, *global* कहलाते हैं। -Global variables are visible from any function (unless shadowed by locals). +ग्लोबल variables किसी भी function से दिखाई देते हैं (जब तक कि लोकल द्वारा छिपा न हो)। -It's a good practice to minimize the use of global variables. Modern code has few or no globals. Most variables reside in their functions. Sometimes though, they can be useful to store project-level data. +ग्लोबल variable के उपयोग को कम करने के लिए यह एक अच्छा अभ्यास है। आधुनिक कोड में कुछ या कोई ग्लोबल्स नहीं हैं। अधिकांश variable अपने functions में रहते हैं। हालांकि कभी-कभी, वे प्रोजेक्ट-स्तरीय डेटा संग्रहीत करने के लिए उपयोगी हो सकते हैं। ``` ## Parameters -We can pass arbitrary data to functions using parameters (also called *function arguments*) . +हम Parameters (जिसे _function arguments_ भी कहा जाता है) का उपयोग करके function को मनमाना डेटा पास कर सकते हैं। -In the example below, the function has two parameters: `from` and `text`. +नीचे दिए गए उदाहरण में, function के दो parameters हैं: `from` और `text`। ```js run function showMessage(*!*from, text*/!*) { // arguments: from, text @@ -152,10 +158,9 @@ showMessage('Ann', "What's up?"); // Ann: What's up? (**) */!* ``` -When the function is called in lines `(*)` and `(**)`, the given values are copied to local variables `from` and `text`. Then the function uses them. - -Here's one more example: we have a variable `from` and pass it to the function. Please note: the function changes `from`, but the change is not seen outside, because a function always gets a copy of the value: +जब function को लाइनों में कॉल किया जाता है `(*)` और `(**)`, तो दिए गए मानों को लोकल variables में कॉपी किया जाता है `from` और `text`। फिर function उनका उपयोग करता है। +यहां एक और उदाहरण दिया गया है: हमारे पास एक variable `from` है और इसे function में पास करें। कृपया ध्यान दें: function `from` को बदलता है, लेकिन परिवर्तन बाहर नहीं देखा जाता है, क्योंकि function को हमेशा मूल्य की एक प्रति प्राप्त होती है: ```js run function showMessage(from, text) { @@ -177,17 +182,19 @@ alert( from ); // Ann ## Default values -If a parameter is not provided, then its value becomes `undefined`. +## डिफॉल्ट वैल्यूज + +यदि कोई parameter प्रदान नहीं किया जाता है, तो उसका मान `undefined` हो जाता है। -For instance, the aforementioned function `showMessage(from, text)` can be called with a single argument: +उदाहरण के लिए, उपरोक्त function `showMessage(from, text)` को एक argument के साथ बुलाया जा सकता है: ```js showMessage("Ann"); ``` -That's not an error. Such a call would output `"*Ann*: undefined"`. There's no `text`, so it's assumed that `text === undefined`. +यह कोई एरर नहीं है। ऐसी कॉल `"*Ann*: undefined"` आउटपुट करेगी। कोई `text` नहीं है, इसलिए यह माना जाता है कि `text === undefined`। -If we want to use a "default" `text` in this case, then we can specify it after `=`: +यदि हम इस मामले में "डिफ़ॉल्ट" `text` का उपयोग करना चाहते हैं, तो हम इसे `=` के बाद उल्लिखत कर सकते हैं: ```js run function showMessage(from, *!*text = "no text given"*/!*) { @@ -197,9 +204,9 @@ function showMessage(from, *!*text = "no text given"*/!*) { showMessage("Ann"); // Ann: no text given ``` -Now if the `text` parameter is not passed, it will get the value `"no text given"` +अब यदि `text` parameter नहीं देना गया हो, तो उसे `"no text given"` मान मिलेगा। -Here `"no text given"` is a string, but it can be a more complex expression, which is only evaluated and assigned if the parameter is missing. So, this is also possible: +यहां `"no text given"` एक स्ट्रिंग है, लेकिन यह एक अधिक जटिल अभिव्यक्ति हो सकती है, जिसका केवल मूल्यांकन किया जाता है और parameter गायब होने पर असाइन किया जाता है। तो, यह भी संभव है: ```js run function showMessage(from, text = anotherFunction()) { @@ -209,45 +216,47 @@ function showMessage(from, text = anotherFunction()) { ``` ```smart header="Evaluation of default parameters" -In JavaScript, a default parameter is evaluated every time the function is called without the respective parameter. +जावास्क्रिप्ट में, हर बार संबंधित parameter के बिना function को कॉल किए जाने पर एक डिफ़ॉल्ट parameter का मूल्यांकन किया जाता है। -In the example above, `anotherFunction()` is called every time `showMessage()` is called without the `text` parameter. +ऊपर दिए गए उदाहरण में, `anotherFunction()` को हर बार `showMessage()` को `text` parameter के बिना कहा जाता है। ``` ### Alternative default parameters -Sometimes it makes sense to set default values for parameters not in the function declaration, but at a later stage, during its execution. +### वैकल्पिक डिफ़ॉल्ट parameters -To check for an omitted parameter, we can compare it with `undefined`: +कभी-कभी function घोषणा में parameter के लिए डिफ़ॉल्ट मान सेट करना समझ में आता है, लेकिन बाद के चरण में, इसके निष्पादन के दौरान भी सेट किया जाता है। + +छोड़े गए पैरामीटर की जांच करने के लिए, हम इसकी तुलना `undefined` से कर सकते हैं: ```js run function showMessage(text) { *!* if (text === undefined) { - text = 'empty message'; + text = 'खाली संदेश'; } */!* alert(text); } -showMessage(); // empty message +showMessage(); // खाली संदेश ``` -...Or we could use the `||` operator: +...या हम `||` ऑपरेटर का उपयोग कर सकते हैं: ```js -// if text parameter is omitted or "" is passed, set it to 'empty' +// यदि टेक्स्ट पैरामीटर छोड़ा गया है या "" पारित किया गया है, तो इसे 'खाली' पर सेट करें function showMessage(text) { text = text || 'empty'; ... } ``` -Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when falsy values, such as `0`, are considered regular: +आधुनिक जावास्क्रिप्ट इंजन [nullish coalescing operator](info:nullish-coalescing-operator) `??` को सपोर्ट करती है| यह तब बेहतर होता है जब `0` जैसे झूठे मूल्यों को नियमित माना जाता है: ```js run -// if there's no "count" parameter, show "unknown" +// यदि कोई "count" पैरामीटर नहीं है, तो "unknown" दिखाएं function showCount(count) { alert(count ?? "unknown"); } @@ -259,9 +268,11 @@ showCount(); // unknown ## Returning a value -A function can return a value back into the calling code as the result. +## एक मान लौटाना + +एक function परिणाम के रूप में एक मान वापस कॉलिंग कोड में वापस कर सकता है। -The simplest example would be a function that sums two values: +सबसे सरल उदाहरण एक ऐसा function होगा जो दो मानों का योग करता है: ```js run no-beautify function sum(a, b) { @@ -272,9 +283,9 @@ let result = sum(1, 2); alert( result ); // 3 ``` -The directive `return` can be in any place of the function. When the execution reaches it, the function stops, and the value is returned to the calling code (assigned to `result` above). +निर्देश `return` function के किसी भी स्थान पर हो सकता है। जब निष्पादन उस तक पहुंच जाता है, तो function बंद हो जाता है, और मान कॉलिंग कोड पर वापस आ जाता है (उपरोक्त `result` को सौंपा गया) -There may be many occurrences of `return` in a single function. For instance: +एक function में `return` की कई घटनाएं हो सकती हैं। उदाहरण के लिए: ```js run function checkAge(age) { @@ -284,23 +295,23 @@ function checkAge(age) { */!* } else { *!* - return confirm('Do you have permission from your parents?'); + return confirm('क्या आपके पास अपने माता-पिता से अनुमति है?'); */!* } } -let age = prompt('How old are you?', 18); +let age = prompt('आपकी उम्र क्या है?', 18); if ( checkAge(age) ) { - alert( 'Access granted' ); + alert( 'प्रवेश करने की अनुमति है' ); } else { - alert( 'Access denied' ); + alert( 'पहुंच अस्वीकृत' ); } ``` -It is possible to use `return` without a value. That causes the function to exit immediately. +बिना मूल्य के `return` का उपयोग करना संभव है। यह function को तुरंत बाहर निकलने का कारण बनता है। -For example: +उदाहरण के लिए: ```js function showMovie(age) { @@ -310,50 +321,52 @@ function showMovie(age) { */!* } - alert( "Showing you the movie" ); // (*) + alert( "आपको फिल्म दिखा रहा है" ); // (*) // ... } ``` -In the code above, if `checkAge(age)` returns `false`, then `showMovie` won't proceed to the `alert`. +ऊपर दिए गए कोड में, अगर ` checkAge(age)` `false` लौटाता है, तो `showMovie` `alert` पर आगे नहीं बढ़ेगा। -````smart header="A function with an empty `return` or without it returns `undefined`" -If a function does not return a value, it is the same as if it returns `undefined`: +````smart header="A function with an empty `return`or without it returns`undefined`" If a function does not return a value, it is the same as if it returns `undefined`: ```js run -function doNothing() { /* empty */ } +function doNothing() { + /* खाली */ +} -alert( doNothing() === undefined ); // true +alert(doNothing() === undefined); // सच ``` -An empty `return` is also the same as `return undefined`: +एक खाली `return` भी `return undefined` जैसा ही है: ```js run function doNothing() { return; } -alert( doNothing() === undefined ); // true +alert(doNothing() === undefined); // सच ``` -```` + +````` ````warn header="Never add a newline between `return` and the value" -For a long expression in `return`, it might be tempting to put it on a separate line, like this: +`return` में एक लंबी अभिव्यक्ति के लिए, इसे एक अलग लाइन पर रखना आकर्षक हो सकता है, जैसे: ```js return (some + long + expression + or + whatever * f(a) + f(b)) ``` -That doesn't work, because JavaScript assumes a semicolon after `return`. That'll work the same as: +यह काम नहीं करता है, क्योंकि `return` के बाद जावास्क्रिप्ट सेमीकोलन लगा देता है । यह उसी तरह काम करेगा: ```js return*!*;*/!* (some + long + expression + or + whatever * f(a) + f(b)) ``` -So, it effectively becomes an empty return. +तो, यह प्रभावी रूप से एक खाली रिटर्न बन जाता है। -If we want the returned expression to wrap across multiple lines, we should start it at the same line as `return`. Or at least put the opening parentheses there as follows: +यदि हम चाहते हैं कि लौटाए गए एक्सप्रेशन को कई लाइनों में लपेटा जाए, तो हमें इसे उसी लाइन से शुरू करना चाहिए जैसे `return`। या कम से कम उद्घाटन कोष्ठक इस प्रकार रखें: ```js return ( @@ -362,82 +375,81 @@ return ( whatever * f(a) + f(b) ) ``` -And it will work just as we expect it to. -```` +और यह वैसे ही काम करेगा जैसा हम उम्मीद करते हैं। +````` -## Naming a function [#function-naming] +## एक function का नामकरण [#function-naming] -Functions are actions. So their name is usually a verb. It should be brief, as accurate as possible and describe what the function does, so that someone reading the code gets an indication of what the function does. +Functions क्रिया हैं। तो उनका नाम आमतौर पर एक क्रिया है। यह संक्षिप्त होना चाहिए, यथासंभव सटीक होना चाहिए और यह वर्णन करना चाहिए कि function क्या करता है, ताकि कोड पढ़ने वाले व्यक्ति को यह संकेत मिल सके कि function क्या करता है। -It is a widespread practice to start a function with a verbal prefix which vaguely describes the action. There must be an agreement within the team on the meaning of the prefixes. +क्रिया को अस्पष्ट रूप से वर्णित करने वाले मौखिक उपसर्ग के साथ function प्रारंभ करना एक व्यापक प्रथा है। उपसर्गों के अर्थ पर टीम के भीतर एक समझौता होना चाहिए। -For instance, functions that start with `"show"` usually show something. +उदाहरण के लिए, `"show"` से शुरू होने वाले फ़ंक्शन आमतौर पर कुछ दिखाते हैं। -Function starting with... +Function की शुरुआत... -- `"get…"` -- return a value, -- `"calc…"` -- calculate something, -- `"create…"` -- create something, -- `"check…"` -- check something and return a boolean, etc. +- `"get…"` -- एक मूल्य वापस करें, +- `"calc…"` -- कुछ गणना करो, +- `"create…"` -- कुछ बनाये, +- `"check…"` -- कुछ जांचें और एक बूलियन लौटाएं, आदि। -Examples of such names: +ऐसे नामों के उदाहरण: ```js no-beautify -showMessage(..) // shows a message -getAge(..) // returns the age (gets it somehow) -calcSum(..) // calculates a sum and returns the result -createForm(..) // creates a form (and usually returns it) -checkPermission(..) // checks a permission, returns true/false +showMessage(..) // एक संदेश दिखाता है +getAge(..) // उम्र लौटाता है (इसे किसी तरह प्राप्त करता है) +calcSum(..) // एक योग की गणना करता है और परिणाम देता है +createForm(..) // एक फॉर्म बनाता है (और आमतौर पर इसे वापस करता है) +checkPermission(..) // अनुमति की जाँच करता है, सही/गलत लौटाता है ``` -With prefixes in place, a glance at a function name gives an understanding what kind of work it does and what kind of value it returns. +उपसर्गों के साथ, function नाम पर एक नज़र यह समझ देती है कि यह किस प्रकार का कार्य करता है और यह किस प्रकार का मूल्य देता है। ```smart header="One function -- one action" -A function should do exactly what is suggested by its name, no more. +एक function को ठीक वही करना चाहिए जो उसके नाम से सुझाया गया है, और नहीं। -Two independent actions usually deserve two functions, even if they are usually called together (in that case we can make a 3rd function that calls those two). +दो स्वतंत्र क्रियाएं आम तौर पर दो functions की सेवा करती हैं, भले ही उन्हें आम तौर पर एक साथ बुलाया जाता है (उस स्थिति में हम एक तीसरा function बना सकते हैं जो उन दोनों को कॉल करता है)। -A few examples of breaking this rule: +इस नियम को तोड़ने के कुछ उदाहरण: -- `getAge` -- would be bad if it shows an `alert` with the age (should only get). -- `createForm` -- would be bad if it modifies the document, adding a form to it (should only create it and return). -- `checkPermission` -- would be bad if it displays the `access granted/denied` message (should only perform the check and return the result). +- `getAge` -- बुरा होगा अगर यह उम्र के साथ एक `alert` दिखाता है (सिर्फ लेना चाहिए )। +- `createForm` -- खराब होगा यदि यह डॉक्यूमेंट को संशोधित करता है, इसमें एक फॉर्म जोड़ता है (केवल इसे बनाना और वापस करना चाहिए)। +- `checkPermission` -- खराब होगा यदि यह `access granted/denied` संदेश प्रदर्शित करता है (केवल जांच करना चाहिए और परिणाम वापस करना चाहिए)। -These examples assume common meanings of prefixes. You and your team are free to agree on other meanings, but usually they're not much different. In any case, you should have a firm understanding of what a prefix means, what a prefixed function can and cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge. +ये उदाहरण उपसर्गों के सामान्य अर्थ ग्रहण करते हैं। आप और आपकी टीम अन्य अर्थों पर सहमत होने के लिए स्वतंत्र हैं, लेकिन आमतौर पर, वे बहुत भिन्न नहीं होते हैं। किसी भी मामले में, आपको इस बात की पक्की समझ होनी चाहिए कि उपसर्ग का क्या अर्थ है, उपसर्ग का function क्या कर सकता है और क्या नहीं। सभी समान-उपसर्ग फ़ंक्शन को नियमों का पालन करना चाहिए। और टीम को ज्ञान साझा करना चाहिए। ``` ```smart header="Ultrashort function names" -Functions that are used *very often* sometimes have ultrashort names. +*अक्सर* उपयोग किए जाने वाले फ़ंक्शंस में कभी-कभी अल्ट्रा-शॉर्ट नाम होते हैं। -For example, the [jQuery](http://jquery.com) framework defines a function with `$`. The [Lodash](http://lodash.com/) library has its core function named `_`. +उदाहरण के लिए, [jQuery](http://jquery.com) फ्रेमवर्क `$` के साथ एक function को परिभाषित करता है। The [Lodash](http://lodash.com/) library का मुख्य function `_` है। -These are exceptions. Generally functions names should be concise and descriptive. +ये अपवाद हैं। आम तौर पर functions नाम संक्षिप्त और वर्णनात्मक होने चाहिए। ``` ## Functions == Comments -Functions should be short and do exactly one thing. If that thing is big, maybe it's worth it to split the function into a few smaller functions. Sometimes following this rule may not be that easy, but it's definitely a good thing. +Functions छोटे होने चाहिए और ठीक एक काम करना चाहिए। अगर वह चीज बड़ी है, तो शायद यह function को कुछ छोटे functions में विभाजित करना बेहतर है। कभी-कभी इस नियम का पालन करना इतना आसान नहीं हो सकता है, लेकिन यह निश्चित रूप से एक अच्छी बात है। -A separate function is not only easier to test and debug -- its very existence is a great comment! +एक अलग function न केवल परीक्षण और डीबग करना आसान है - इसका अस्तित्व एक महान comment है! -For instance, compare the two functions `showPrimes(n)` below. Each one outputs [prime numbers](https://en.wikipedia.org/wiki/Prime_number) up to `n`. +उदाहरण के लिए, नीचे दिए गए दो कार्यों `showPrimes(n)` की तुलना करें। हर एक `n` तक [अभाज्य संख्याएँ](https://en.wikipedia.org/wiki/Prime_number) आउटपुट करता है। -The first variant uses a label: +पहला संस्करण एक लेबल का उपयोग करता है: ```js function showPrimes(n) { nextPrime: for (let i = 2; i < n; i++) { - for (let j = 2; j < i; j++) { if (i % j == 0) continue nextPrime; } - alert( i ); // a prime + alert(i); // एक अभाज्य संख्या } } ``` -The second variant uses an additional function `isPrime(n)` to test for primality: +दूसरा संस्करण अभाज्यता के परीक्षण के लिए एक अतिरिक्त function `isPrime(n)` का उपयोग करता है: ```js function showPrimes(n) { @@ -445,7 +457,7 @@ function showPrimes(n) { for (let i = 2; i < n; i++) { *!*if (!isPrime(i)) continue;*/!* - alert(i); // a prime + alert(i); // एक अभाज्य संख्या } } @@ -457,13 +469,13 @@ function isPrime(n) { } ``` -The second variant is easier to understand, isn't it? Instead of the code piece we see a name of the action (`isPrime`). Sometimes people refer to such code as *self-describing*. +दूसरा संस्करण समझना आसान है, है ना? कोड पीस के बजाय हम क्रिया का एक नाम देखते हैं (`isPrime`)। कभी-कभी लोग ऐसे कोड को _self-describing_ कहते हैं। -So, functions can be created even if we don't intend to reuse them. They structure the code and make it readable. +इसलिए, function बनाए जा सकते हैं, भले ही हम उनका पुन: उपयोग करने का इरादा न रखते हों। वे कोड की संरचना करते हैं और इसे पठनीय बनाते हैं। -## Summary +## सारांश -A function declaration looks like this: +एक function घोषणा इस तरह दिखती है: ```js function name(parameters, delimited, by, comma) { @@ -471,18 +483,18 @@ function name(parameters, delimited, by, comma) { } ``` -- Values passed to a function as parameters are copied to its local variables. -- A function may access outer variables. But it works only from inside out. The code outside of the function doesn't see its local variables. -- A function can return a value. If it doesn't, then its result is `undefined`. +- किसी function को दिए गए मान parameters के रूप में उसके local variables में कॉपी किए जाते हैं। +- एक function बाहरी variables का इस्तेमाल कर सकता है। लेकिन यह केवल अंदर से बाहर काम करता है। function के बाहर का कोड इसके स्थानीय variables नहीं देखता है। +- एक function एक मान वापस कर सकता है। यदि ऐसा नहीं होता है, तो इसका परिणाम `undefined` होता है। -To make the code clean and easy to understand, it's recommended to use mainly local variables and parameters in the function, not outer variables. +कोड को साफ और समझने में आसान बनाने के लिए, function में मुख्य रूप से local variables और parameter का उपयोग करने की अनुशंसा की जाती है, outer variables नहीं। -It is always easier to understand a function which gets parameters, works with them and returns a result than a function which gets no parameters, but modifies outer variables as a side-effect. +ऐसे function को समझना हमेशा आसान होता है जो पैरामीटर प्राप्त करता है, उनके साथ काम करता है, और किसी ऐसे फ़ंक्शन की तुलना में परिणाम देता है जिसमें कोई पैरामीटर नहीं होता है, लेकिन बाहरी variables को साइड-इफेक्ट के रूप में संशोधित करता है। -Function naming: +Function नामकरण: -- A name should clearly describe what the function does. When we see a function call in the code, a good name instantly gives us an understanding what it does and returns. -- A function is an action, so function names are usually verbal. -- There exist many well-known function prefixes like `create…`, `show…`, `get…`, `check…` and so on. Use them to hint what a function does. +- एक नाम स्पष्ट रूप से वर्णन करना चाहिए कि function क्या करता है। जब हम कोड में एक function कॉल देखते हैं, तो एक अच्छा नाम हमें तुरंत समझा देता है कि यह क्या करता है और क्या वापस लौटता है। +- एक function एक क्रिया है, इसलिए function नाम आमतौर पर मौखिक होते हैं। +- कई प्रसिद्ध function प्रीफ़िक्स मौजूद हैं जैसे `create…`, `show…`, `get…`, `check…` और इसी तरह। function क्या करता है यह संकेत देने के लिए उनका उपयोग करें। -Functions are the main building blocks of scripts. Now we've covered the basics, so we actually can start creating and using them. But that's only the beginning of the path. We are going to return to them many times, going more deeply into their advanced features. +Function स्क्रिप्ट के मुख्य निर्माण खंड हैं। अब हमने मूल बातें शामिल कर ली हैं, इसलिए हम वास्तव में उन्हें बनाना और उनका उपयोग करना शुरू कर सकते हैं। लेकिन यह सिर्फ रास्ते की शुरुआत है। हम कई बार उनके पास वापस जायेंगे, उन्नत सुविधाओं में और अधिक गहराई से इनको जानेंगे। From b6328927088d6e23fe7b6048d24952c51df9024a Mon Sep 17 00:00:00 2001 From: rskhan167 Date: Fri, 10 Sep 2021 00:44:08 +0530 Subject: [PATCH 09/43] fix translate --- .../1-if-else-required/solution.md | 1 - .../1-if-else-required/task.md | 14 ++++---------- .../2-rewrite-function-question-or/solution.md | 7 ++----- .../2-rewrite-function-question-or/task.md | 16 ++++------------ .../15-function-basics/3-min/solution.md | 3 --- .../15-function-basics/3-min/task.md | 12 ++++-------- 6 files changed, 14 insertions(+), 39 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md b/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md index bb54ffb54..7e1a36a09 100644 --- a/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md +++ b/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md @@ -1,2 +1 @@ -No difference. कोई फर्क नहीं। diff --git a/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md b/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md index c1d83124c..3678b4034 100644 --- a/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md +++ b/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md @@ -2,14 +2,10 @@ importance: 4 --- -# Is "else" required? - # क्या "else" आवश्यक है? -The following function returns `true` if the parameter `age` is greater than `18`. -यदि `age` पैरामीटर `18` से अधिक है, तो निम्नलिखित फ़ंक्शन `true` लौटाता है। +यदि `age` parameter `18` से अधिक है, तो निम्नलिखित function `true` लौटाता है। -Otherwise it asks for a confirmation and returns its result: अन्यथा, यह एक पुष्टिकरण मांगता है और अपना परिणाम देता है: ```js @@ -19,14 +15,13 @@ function checkAge(age) { *!* } else { // ... - return confirm('Did parents allow you?'); + return confirm('क्या माता-पिता ने आपको अनुमति दी थी?'); } */!* } ``` -Will the function work differently if `else` is removed? -यदि `else` हटा दिया जाता है तो क्या फ़ंक्शन अलग तरह से काम करेगा? +यदि `else` हटा दिया जाता है तो क्या function अलग तरह से काम करेगा? ```js function checkAge(age) { @@ -35,10 +30,9 @@ function checkAge(age) { } *!* // ... - return confirm('Did parents allow you?'); + return confirm('क्या माता-पिता ने आपको अनुमति दी थी?'); */!* } ``` -Is there any difference in the behavior of these two variants? क्या इन दोनों रूपों के व्यवहार में कोई अंतर है? diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md index f73af505b..f4caab6bb 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md @@ -1,20 +1,17 @@ -Using a question mark operator `'?'`: प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?`: ```js function checkAge(age) { - return (age > 18) ? true : confirm('Did parents allow you?'); + return age > 18 ? true : confirm("Did parents allow you?"); } ``` -Using OR `||` (the shortest variant): OR ऑपरेटर का उपयोग करते हुए `||` (सबसे छोटा संस्करण) ```js function checkAge(age) { - return (age > 18) || confirm('Did parents allow you?'); + return age > 18 || confirm("Did parents allow you?"); } ``` -Note that the parentheses around `age > 18` are not required here. They exist for better readabiltiy. ध्यान दें कि यहां `age > 18` के आसपास के कोष्ठकों की आवश्यकता नहीं है। वे बेहतर पठनीयता के लिए मौजूद हैं। diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index bd204330c..0be0d9ccb 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -2,14 +2,10 @@ importance: 4 --- -# Rewrite the function using '?' or '||' +# '?' या '||' का उपयोग करके function को फिर से लिखें| -# '?' या '||' का उपयोग करके फ़ंक्शन को फिर से लिखें| +यदि `age` parameter `18` से अधिक है, तो निम्नलिखित function `true` लौटाता है। -The following function returns `true` if the parameter `age` is greater than `18`. -यदि `age` पैरामीटर `18` से अधिक है, तो निम्नलिखित फ़ंक्शन `true` लौटाता है। - -Otherwise it asks for a confirmation and returns its result. अन्यथा, यह एक पुष्टिकरण मांगता है और अपना परिणाम देता है: ```js @@ -17,18 +13,14 @@ function checkAge(age) { if (age > 18) { return true; } else { - return confirm('Did parents allow you?'); + return confirm("क्या माता-पिता ने आपको अनुमति दी थी?"); } } ``` -Rewrite it, to perform the same, but without `if`, in a single line. इसे फिर से लिखें, वही प्रदर्शन करने के लिए, लेकिन बिना `if` के, एक पंक्ति में। -Make two variants of `checkAge`: -'checkAge' के दो प्रकार बनाएं: +`checkAge` के दो प्रकार बनाएं: -1. Using a question mark operator `?` -2. Using OR `||` 1. प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?` 2. OR ऑपरेटर का उपयोग करते हुए `||` diff --git a/1-js/02-first-steps/15-function-basics/3-min/solution.md b/1-js/02-first-steps/15-function-basics/3-min/solution.md index f46c297bb..e3f1c0d47 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/solution.md +++ b/1-js/02-first-steps/15-function-basics/3-min/solution.md @@ -1,4 +1,3 @@ -A solution using `if`: `if` का उपयोग करके एक हल: ```js @@ -11,7 +10,6 @@ function min(a, b) { } ``` -A solution with a question mark operator `'?'`: प्रश्न चिह्न ऑपरेटर `'?'` के साथ एक हल: ```js @@ -20,5 +18,4 @@ function min(a, b) { } ``` -P.S. In the case of an equality `a == b` it does not matter what to return. नोट: समानता `a == b` के मामले में यह मायने नहीं रखता कि क्या लौटाया जाए। diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index b6910a40d..1b30f832c 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -4,16 +4,12 @@ importance: 1 # Function min(a, b) -# फंक्शन min(a, b) +एक function लिखें `min(a,b)` जो कम से कम दो नंबर `a` और `b` लौटाता है। -Write a function `min(a,b)` which returns the least of two numbers `a` and `b`. -एक फ़ंक्शन लिखें `min(a,b)` जो कम से कम दो नंबर `a` और `b` लौटाता है। - -For instance: उदाहरण के लिए: ```js -min(2, 5) == 2 -min(3, -1) == -1 -min(1, 1) == 1 +min(2, 5) == 2; +min(3, -1) == -1; +min(1, 1) == 1; ``` From 1d427532658866ba136a10fb5033c2dd3e5147db Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 10 Sep 2021 00:47:24 +0530 Subject: [PATCH 10/43] fix IDE's autochanges --- .../2-rewrite-function-question-or/solution.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md index f4caab6bb..c212e65b0 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md @@ -2,7 +2,7 @@ ```js function checkAge(age) { - return age > 18 ? true : confirm("Did parents allow you?"); + return (age > 18) ? true : confirm('क्या माता-पिता ने आपको अनुमति दी थी?'); } ``` @@ -10,7 +10,7 @@ OR ऑपरेटर का उपयोग करते हुए `||` (सब ```js function checkAge(age) { - return age > 18 || confirm("Did parents allow you?"); + return (age > 18) || confirm('क्या माता-पिता ने आपको अनुमति दी थ?'); } ``` From 93aa7be037f7f182ba887b14760adcf28c1e3fdc Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 10 Sep 2021 00:52:03 +0530 Subject: [PATCH 11/43] fix IDE's autochanges --- 1-js/02-first-steps/15-function-basics/article.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 1c635dd49..8fa8a9aec 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -18,7 +18,7 @@ function बनाने के लिए हम एक _function declaration_ ```js function showMessage() { - alert("सभी को नमस्कार!"); + alert( "सभी को नमस्कार!" ); } ``` @@ -335,7 +335,7 @@ function doNothing() { /* खाली */ } -alert(doNothing() === undefined); // सच +alert( doNothing() === undefined ); // सच ``` एक खाली `return` भी `return undefined` जैसा ही है: @@ -345,7 +345,7 @@ function doNothing() { return; } -alert(doNothing() === undefined); // सच +alert( doNothing() === undefined ); // सच ``` ````` @@ -376,7 +376,7 @@ return ( ) ``` और यह वैसे ही काम करेगा जैसा हम उम्मीद करते हैं। -````` +```` ## एक function का नामकरण [#function-naming] @@ -444,7 +444,7 @@ function showPrimes(n) { if (i % j == 0) continue nextPrime; } - alert(i); // एक अभाज्य संख्या + alert( i ); // एक अभाज्य संख्या } } ``` From f39ab2bb3308b2240fa3c574e17bf2aaa3e7dcac Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 10 Sep 2021 00:55:09 +0530 Subject: [PATCH 12/43] fix IDE's autochanges --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 1b30f832c..397953d8b 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -9,7 +9,7 @@ importance: 1 उदाहरण के लिए: ```js -min(2, 5) == 2; -min(3, -1) == -1; -min(1, 1) == 1; +min(2, 5) == 2 +min(3, -1) == -1 +min(1, 1) == 1 ``` From 5bf0d16798ec15067cc5afc91e8a0c3d533d3fa4 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 14 Sep 2021 14:33:25 +0530 Subject: [PATCH 13/43] fix some translations --- 1-js/02-first-steps/15-function-basics/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 8fa8a9aec..24a98af17 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -335,7 +335,7 @@ function doNothing() { /* खाली */ } -alert( doNothing() === undefined ); // सच +alert( doNothing() === undefined ); // true ``` एक खाली `return` भी `return undefined` जैसा ही है: @@ -345,7 +345,7 @@ function doNothing() { return; } -alert( doNothing() === undefined ); // सच +alert( doNothing() === undefined ); // true ``` ````` From badd33b4039cd98c6b51e2d5713f443742b571c5 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 09:30:10 +0530 Subject: [PATCH 14/43] Update task.md --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 397953d8b..27a40df27 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -4,7 +4,7 @@ importance: 1 # Function min(a, b) -एक function लिखें `min(a,b)` जो कम से कम दो नंबर `a` और `b` लौटाता है। +एक फ़ंक्शन लिखें `min(a,b)` जो `a` और `b` नंबर में सबसे छोटा है उसको लौटाता है। उदाहरण के लिए: From 1eac2810eb474c0403cfd39d16d038a00c404ef0 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 09:38:04 +0530 Subject: [PATCH 15/43] Update task.md --- 1-js/02-first-steps/15-function-basics/4-pow/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index 26b090f09..931fd96b1 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -4,7 +4,7 @@ importance: 4 # Function pow(x,n) -एक function लिखें `pow(x,n)` जो `x` को `n` के शक्ति में लौटाता है। या, दूसरे शब्दों में, `x` को अपने आप से `n` गुणा से गुणा करता है और परिणाम देता है। +एक फ़ंक्शन लिखें `pow(x,n)` जो `x` को `n` की घात में लौटाता है। या, दूसरे शब्दों में, `x` को अपने आप से `n` बार गुणा करता है और परिणाम देता है। ```js pow(3, 2) = 3 * 3 = 9 From de48b642651ad29c8b111fb97569bb2b7b6d5544 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 09:42:59 +0530 Subject: [PATCH 16/43] Update task.md --- 1-js/02-first-steps/15-function-basics/4-pow/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index 931fd96b1..097f9cf8a 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -16,4 +16,4 @@ pow(1, 100) = 1 * 1 * ...* 1 = 1 [demo] -नोट: इस टास्क में function को केवल `n` के प्राकृतिक मान का समर्थन करना चाहिए: `1` से ऊपर के पूर्णांक। +नोट: इस टास्क में फ़ंक्शन को केवल `n` के प्राकृतिक मानों को स्वीकार करना चाहिए: `1` से ऊपर के पूर्णांक। From dc463a3f02676c7038644921e913d9e9d5b102cc Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 09:56:41 +0530 Subject: [PATCH 17/43] Update article.md --- 1-js/02-first-steps/15-function-basics/article.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 24a98af17..a9c130618 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -1,18 +1,16 @@ # Functions -अक्सर हमें स्क्रिप्ट के कई स्थानों पर इसी तरह की कार्रवाई करने की आवश्यकता होती है। +अक्सर हमें स्क्रिप्ट के कई स्थानों पर इसी तरह की क्रिया करने की आवश्यकता होती है। -उदाहरण के लिए, जब कोई परिदर्शक इन करता है, लॉग आउट करता है और शायद कहीं और एक अच्छा दिखने वाला संदेश दिखाना चाहता है। +उदाहरण के लिए, हमें एक अच्छा दिखने वाला संदेश दिखाना चाहिए जब कोई आगंतुक लॉग इन करता है, लॉग आउट करता है। Functions प्रोग्राम के मुख्य "बिल्डिंग ब्लॉक्स" हैं। वे बिना दोहराव के कोड को कई बार कॉल करने की अनुमति देते हैं। -हम पहले से ही बिल्ट-इन function के उदाहरण देख चुके हैं, जैसे `अलर्ट (संदेश)`, `प्रॉम्प्ट (संदेश, डिफ़ॉल्ट)` और `पुष्टि करें (प्रश्न)`। लेकिन हम अपने स्वयं के functions भी बना सकते हैं। - -## Function Declaration +हम पहले से ही बिल्ट-इन function के उदाहरण देख चुके हैं, जैसे `alert(message)`, `prompt(message, default)` और `confirm(question)`। लेकिन हम अपने स्वयं के functions भी बना सकते हैं। ## Function घोषणा -function बनाने के लिए हम एक _function declaration_ का उपयोग कर सकते हैं। +function बनाने के लिए हम एक _function घोषणा_ का उपयोग कर सकते हैं। यह इस तरह दिख रहा है: @@ -22,7 +20,7 @@ function showMessage() { } ``` -`function` कीवर्ड पहले जाता है, फिर _name of the function_ जाता है, फिर कोष्ठक के बीच _parameters_ की एक सूची (उपरोक्त उदाहरण में खाली) और अंत में function का कोड, जिसे "the function body" भी कहा जाता है , घुंघराले ब्रेसिज़ के बीच। +`function` कीवर्ड पहले जाता है, फिर _function का नाम_ जाता है, फिर कोष्ठक के बीच _parameters_ की एक सूची (उपरोक्त उदाहरण में खाली) और अंत में function का कोड, जिसे "function बॉडी" भी कहा जाता है, घुंघराले ब्रेसिज़ के बीच। ```js function name(parameters) { From 300a818c97c60cf02a2b1e6d078f225b8169b69c Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:20:44 +0530 Subject: [PATCH 18/43] Update task.md --- .../15-function-basics/2-rewrite-function-question-or/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index 0be0d9ccb..287512b0d 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -18,7 +18,7 @@ function checkAge(age) { } ``` -इसे फिर से लिखें, वही प्रदर्शन करने के लिए, लेकिन बिना `if` के, एक पंक्ति में। +इसे फिर से लिखें, वही कार्य करने के लिए, लेकिन बिना `if` के, एक पंक्ति में। `checkAge` के दो प्रकार बनाएं: From 582983e4c320489b2c4c97a08dcc84a1ee5669a2 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:33:33 +0530 Subject: [PATCH 19/43] Update article.md --- 1-js/02-first-steps/15-function-basics/article.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index a9c130618..0e8cdcbe7 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -12,7 +12,7 @@ Functions प्रोग्राम के मुख्य "बिल्डि function बनाने के लिए हम एक _function घोषणा_ का उपयोग कर सकते हैं। -यह इस तरह दिख रहा है: +यह इस तरह दिखता है: ```js function showMessage() { @@ -49,8 +49,6 @@ showMessage(); यदि हमें कभी भी संदेश या उसके दिखाए जाने के तरीके को बदलने की आवश्यकता होती है, तो यह कोड को एक ही स्थान पर संशोधित करने के लिए पर्याप्त है: वह function जो इसे आउटपुट करता है। -## Local variables - ## लोकल variables किसी function के अंदर घोषित एक variable केवल उस function के अंदर ही दिखाई देता है। @@ -71,8 +69,6 @@ showMessage(); // हैलो, मैं जावास्क्रिप् alert( message ); // <-- Error! variable function के लिए स्थानीय है ``` -## Outer variables - ## बाहरी variables एक function बाहरी variable को भी एक्सेस कर सकता है, उदाहरण के लिए: @@ -178,8 +174,6 @@ showMessage(from, "Hello"); // *Ann*: Hello alert( from ); // Ann ``` -## Default values - ## डिफॉल्ट वैल्यूज यदि कोई parameter प्रदान नहीं किया जाता है, तो उसका मान `undefined` हो जाता है। @@ -219,8 +213,6 @@ function showMessage(from, text = anotherFunction()) { ऊपर दिए गए उदाहरण में, `anotherFunction()` को हर बार `showMessage()` को `text` parameter के बिना कहा जाता है। ``` -### Alternative default parameters - ### वैकल्पिक डिफ़ॉल्ट parameters कभी-कभी function घोषणा में parameter के लिए डिफ़ॉल्ट मान सेट करना समझ में आता है, लेकिन बाद के चरण में, इसके निष्पादन के दौरान भी सेट किया जाता है। @@ -264,8 +256,6 @@ showCount(null); // unknown showCount(); // unknown ``` -## Returning a value - ## एक मान लौटाना एक function परिणाम के रूप में एक मान वापस कॉलिंग कोड में वापस कर सकता है। From c8a43e6664bf72066570d47eb9eeeab8b5f2ac0b Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:39:57 +0530 Subject: [PATCH 20/43] Update article.md --- 1-js/02-first-steps/15-function-basics/article.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 0e8cdcbe7..1f63d6cd8 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -335,8 +335,7 @@ function doNothing() { alert( doNothing() === undefined ); // true ``` - -````` +```` ````warn header="Never add a newline between `return` and the value" `return` में एक लंबी अभिव्यक्ति के लिए, इसे एक अलग लाइन पर रखना आकर्षक हो सकता है, जैसे: From 1b5f2a9796450f07f464b0973ee21768986984eb Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:53:01 +0530 Subject: [PATCH 21/43] Update article.md --- 1-js/02-first-steps/15-function-basics/article.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 1f63d6cd8..c7c24fe70 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -107,7 +107,7 @@ alert( userName ); // *!*Bob*/!*, मान function द्वारा सं बाहरी variable का उपयोग केवल तभी किया जाता है जब कोई लोकल न हो। -यदि function के अंदर एक ही नामित variable घोषित किया गया है तो यह _shadows_ बाहरी है। उदाहरण के लिए, नीचे दिए गए कोड में function लोकल `userName` का उपयोग करता है। बाहरी को अनदेखा किया जाता है: +यदि फ़ंक्शन के अंदर एक ही नामित variable घोषित किया जाता है तो यह बाहरी वाले variable को अनदेखा कर देता है। उदाहरण के लिए, नीचे दिए गए कोड में function लोकल `userName` का उपयोग करता है। बाहरी को अनदेखा किया जाता है: ```js run let userName = 'John'; @@ -128,11 +128,11 @@ alert( userName ); // *!*John*/!*, अपरिवर्तित, function ब ``` ```smart header="Global variables" -किसी function के बाहर घोषित variables, जैसे उपरोक्त कोड में बाहरी `userName`, *global* कहलाते हैं। +किसी function के बाहर घोषित variables, जैसे उपरोक्त कोड में बाहरी `userName`, *ग्लोबल* कहलाते हैं। ग्लोबल variables किसी भी function से दिखाई देते हैं (जब तक कि लोकल द्वारा छिपा न हो)। -ग्लोबल variable के उपयोग को कम करने के लिए यह एक अच्छा अभ्यास है। आधुनिक कोड में कुछ या कोई ग्लोबल्स नहीं हैं। अधिकांश variable अपने functions में रहते हैं। हालांकि कभी-कभी, वे प्रोजेक्ट-स्तरीय डेटा संग्रहीत करने के लिए उपयोगी हो सकते हैं। +ग्लोबल variables के उपयोग को कम करना अच्छा अभ्यास है। आधुनिक कोड में कुछ या कोई ग्लोबल्स नहीं हैं। अधिकांश variable अपने functions में रहते हैं। हालांकि कभी-कभी, वे प्रोजेक्ट-स्तरीय डेटा संग्रहीत करने के लिए उपयोगी हो सकते हैं। ``` ## Parameters From 97871c63506ecc9182c66fa75bae615244719692 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:08:52 +0530 Subject: [PATCH 22/43] Update task.md --- 1-js/02-first-steps/15-function-basics/4-pow/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index 097f9cf8a..aa7e9820f 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -12,7 +12,7 @@ pow(3, 3) = 3 * 3 * 3 = 27 pow(1, 100) = 1 * 1 * ...* 1 = 1 ``` -एक वेब-पेज बनाएं जो `x` और `n` के लिए संकेत देता है, और फिर `pow(x,n)` का परिणाम दिखाता है। +एक वेब पेज बनाएं जो `x` और `n` के लिए प्रोम्प्ट करता है, और फिर `pow(x,n)` का परिणाम दिखाता है। [demo] From 4dd3856cc1657611b1b7646b505cbcb8411a6d21 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:34:14 +0530 Subject: [PATCH 23/43] Update task.md --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 27a40df27..5d1525214 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -4,7 +4,7 @@ importance: 1 # Function min(a, b) -एक फ़ंक्शन लिखें `min(a,b)` जो `a` और `b` नंबर में सबसे छोटा है उसको लौटाता है। +एक फ़ंक्शन लिखें `min(a,b)` जो `a` और `b` नंबर में जो सबसे छोटा है उसको लौटाता है। उदाहरण के लिए: From 6b4f6823f7d8a8767bba0f15944a69fe180d1ff3 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:25:10 +0530 Subject: [PATCH 24/43] Update task.md --- .../15-function-basics/2-rewrite-function-question-or/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index 287512b0d..59d0fc840 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -18,7 +18,7 @@ function checkAge(age) { } ``` -इसे फिर से लिखें, वही कार्य करने के लिए, लेकिन बिना `if` के, एक पंक्ति में। +इस function को फिर से लिखें, लेकिन बिना `if` के, एक पंक्ति में। `checkAge` के दो प्रकार बनाएं: From 1ff58cc7268455391e6cb2529a13a8d65c4e716c Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:27:42 +0530 Subject: [PATCH 25/43] Update task.md --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 5d1525214..56af1f434 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -4,7 +4,7 @@ importance: 1 # Function min(a, b) -एक फ़ंक्शन लिखें `min(a,b)` जो `a` और `b` नंबर में जो सबसे छोटा है उसको लौटाता है। +एक फ़ंक्शन लिखें `min(a,b)` जो `a` और `b` नंबर में से जो सबसे छोटा है उसको लौटाता हो। उदाहरण के लिए: From 5601c3366081621e0849866f6d3c2c064a36bd5c Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:29:34 +0530 Subject: [PATCH 26/43] Update task.md --- 1-js/02-first-steps/15-function-basics/4-pow/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index aa7e9820f..5b1d325a8 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -12,7 +12,7 @@ pow(3, 3) = 3 * 3 * 3 = 27 pow(1, 100) = 1 * 1 * ...* 1 = 1 ``` -एक वेब पेज बनाएं जो `x` और `n` के लिए प्रोम्प्ट करता है, और फिर `pow(x,n)` का परिणाम दिखाता है। +एक वेब पेज बनाएं जो `x` और `n` के लिए prompt करता है, और फिर `pow(x,n)` का परिणाम दिखाता है। [demo] From 691397181d632e4a86e9a516fbc488c7c93e439f Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:30:20 +0530 Subject: [PATCH 27/43] Update task.md --- 1-js/02-first-steps/15-function-basics/4-pow/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index 5b1d325a8..af06008b4 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -16,4 +16,4 @@ pow(1, 100) = 1 * 1 * ...* 1 = 1 [demo] -नोट: इस टास्क में फ़ंक्शन को केवल `n` के प्राकृतिक मानों को स्वीकार करना चाहिए: `1` से ऊपर के पूर्णांक। +नोट: इस टास्क में function को केवल `n` के प्राकृतिक मानों को स्वीकार करना चाहिए: `1` से ऊपर के पूर्णांक। From f9696ddd5a038b5378eeea39bc8bf54b35d188b2 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:58:33 +0530 Subject: [PATCH 28/43] Update article.md --- .../15-function-basics/article.md | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index c7c24fe70..198d0ede3 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -98,7 +98,7 @@ function showMessage() { alert(message); } -alert( userName ); // *!*John*/!* फ़ंक्शन कॉल से पहले +alert( userName ); // *!*John*/!* function कॉल से पहले showMessage(); @@ -107,7 +107,7 @@ alert( userName ); // *!*Bob*/!*, मान function द्वारा सं बाहरी variable का उपयोग केवल तभी किया जाता है जब कोई लोकल न हो। -यदि फ़ंक्शन के अंदर एक ही नामित variable घोषित किया जाता है तो यह बाहरी वाले variable को अनदेखा कर देता है। उदाहरण के लिए, नीचे दिए गए कोड में function लोकल `userName` का उपयोग करता है। बाहरी को अनदेखा किया जाता है: +यदि function के अंदर एक ही नामित variable घोषित किया जाता है तो यह बाहरी वाले variable को अनदेखा कर देता है। उदाहरण के लिए, नीचे दिए गए कोड में function लोकल `userName` का उपयोग करता है। बाहरी को अनदेखा किया जाता है: ```js run let userName = 'John'; @@ -121,7 +121,7 @@ function showMessage() { alert(message); } -// फ़ंक्शन अपना स्वयं का userName बनाएगा और उसका उपयोग करेगा +// function अपना स्वयं का userName बनाएगा और उसका उपयोग करेगा showMessage(); alert( userName ); // *!*John*/!*, अपरिवर्तित, function बाहरी variable का उपयोग नहीं करता है @@ -210,14 +210,14 @@ function showMessage(from, text = anotherFunction()) { ```smart header="Evaluation of default parameters" जावास्क्रिप्ट में, हर बार संबंधित parameter के बिना function को कॉल किए जाने पर एक डिफ़ॉल्ट parameter का मूल्यांकन किया जाता है। -ऊपर दिए गए उदाहरण में, `anotherFunction()` को हर बार `showMessage()` को `text` parameter के बिना कहा जाता है। +ऊपर दिए गए उदाहरण में, `another function()` को हर बार कॉल किया जाता है जब भी `showMessage()` को `text` parameter के बिना कॉल किया जाता है। ``` ### वैकल्पिक डिफ़ॉल्ट parameters कभी-कभी function घोषणा में parameter के लिए डिफ़ॉल्ट मान सेट करना समझ में आता है, लेकिन बाद के चरण में, इसके निष्पादन के दौरान भी सेट किया जाता है। -छोड़े गए पैरामीटर की जांच करने के लिए, हम इसकी तुलना `undefined` से कर सकते हैं: +छोड़े गए parameter की जांच करने के लिए, हम इसकी तुलना `undefined` से कर सकते हैं: ```js run function showMessage(text) { @@ -236,7 +236,7 @@ showMessage(); // खाली संदेश ...या हम `||` ऑपरेटर का उपयोग कर सकते हैं: ```js -// यदि टेक्स्ट पैरामीटर छोड़ा गया है या "" पारित किया गया है, तो इसे 'खाली' पर सेट करें +// यदि टेक्स्ट parameter छोड़ा गया है या "" पास किया गया है, तो इसे 'empty' पर सेट करें function showMessage(text) { text = text || 'empty'; ... @@ -246,7 +246,7 @@ function showMessage(text) { आधुनिक जावास्क्रिप्ट इंजन [nullish coalescing operator](info:nullish-coalescing-operator) `??` को सपोर्ट करती है| यह तब बेहतर होता है जब `0` जैसे झूठे मूल्यों को नियमित माना जाता है: ```js run -// यदि कोई "count" पैरामीटर नहीं है, तो "unknown" दिखाएं +// यदि कोई "count" parameter नहीं है, तो "unknown" दिखाएं function showCount(count) { alert(count ?? "unknown"); } @@ -258,7 +258,7 @@ showCount(); // unknown ## एक मान लौटाना -एक function परिणाम के रूप में एक मान वापस कॉलिंग कोड में वापस कर सकता है। +एक function परिणाम के रूप में एक मान वापस कॉलिंग कोड में लौटा सकता है। सबसे सरल उदाहरण एक ऐसा function होगा जो दो मानों का योग करता है: @@ -283,7 +283,7 @@ function checkAge(age) { */!* } else { *!* - return confirm('क्या आपके पास अपने माता-पिता से अनुमति है?'); + return confirm('क्या आपके पास अपने माता-पिता की अनुमति है?'); */!* } } @@ -314,14 +314,12 @@ function showMovie(age) { } ``` -ऊपर दिए गए कोड में, अगर ` checkAge(age)` `false` लौटाता है, तो `showMovie` `alert` पर आगे नहीं बढ़ेगा। +ऊपर दिए गए कोड में, अगर `checkAge(age)` `false` लौटाता है, तो `showMovie` `alert` पर आगे नहीं बढ़ेगा। ````smart header="A function with an empty `return`or without it returns`undefined`" If a function does not return a value, it is the same as if it returns `undefined`: ```js run -function doNothing() { - /* खाली */ -} +function doNothing() { /* खाली */ } alert( doNothing() === undefined ); // true ``` @@ -344,7 +342,7 @@ alert( doNothing() === undefined ); // true return (some + long + expression + or + whatever * f(a) + f(b)) ``` -यह काम नहीं करता है, क्योंकि `return` के बाद जावास्क्रिप्ट सेमीकोलन लगा देता है । यह उसी तरह काम करेगा: +यह काम नहीं करता है, क्योंकि `return` के बाद जावास्क्रिप्ट सेमीकोलन लगा देता है। यह उसी तरह काम करेगा: ```js return*!*;*/!* @@ -365,13 +363,13 @@ return ( और यह वैसे ही काम करेगा जैसा हम उम्मीद करते हैं। ```` -## एक function का नामकरण [#function-naming] +## Function का नामकरण [#function-naming] Functions क्रिया हैं। तो उनका नाम आमतौर पर एक क्रिया है। यह संक्षिप्त होना चाहिए, यथासंभव सटीक होना चाहिए और यह वर्णन करना चाहिए कि function क्या करता है, ताकि कोड पढ़ने वाले व्यक्ति को यह संकेत मिल सके कि function क्या करता है। क्रिया को अस्पष्ट रूप से वर्णित करने वाले मौखिक उपसर्ग के साथ function प्रारंभ करना एक व्यापक प्रथा है। उपसर्गों के अर्थ पर टीम के भीतर एक समझौता होना चाहिए। -उदाहरण के लिए, `"show"` से शुरू होने वाले फ़ंक्शन आमतौर पर कुछ दिखाते हैं। +उदाहरण के लिए, `"show"` से शुरू होने वाले function आमतौर पर कुछ दिखाते हैं। Function की शुरुआत... @@ -393,21 +391,21 @@ checkPermission(..) // अनुमति की जाँच करता ह उपसर्गों के साथ, function नाम पर एक नज़र यह समझ देती है कि यह किस प्रकार का कार्य करता है और यह किस प्रकार का मूल्य देता है। ```smart header="One function -- one action" -एक function को ठीक वही करना चाहिए जो उसके नाम से सुझाया गया है, और नहीं। +एक function को ठीक वही करना चाहिए जो उसके नाम से सुझाया गया है, और कुछ नहीं। दो स्वतंत्र क्रियाएं आम तौर पर दो functions की सेवा करती हैं, भले ही उन्हें आम तौर पर एक साथ बुलाया जाता है (उस स्थिति में हम एक तीसरा function बना सकते हैं जो उन दोनों को कॉल करता है)। इस नियम को तोड़ने के कुछ उदाहरण: -- `getAge` -- बुरा होगा अगर यह उम्र के साथ एक `alert` दिखाता है (सिर्फ लेना चाहिए )। +- `getAge` -- बुरा होगा अगर यह उम्र के साथ एक `alert` दिखाता है (सिर्फ उम्र लेना चाहिए)। - `createForm` -- खराब होगा यदि यह डॉक्यूमेंट को संशोधित करता है, इसमें एक फॉर्म जोड़ता है (केवल इसे बनाना और वापस करना चाहिए)। - `checkPermission` -- खराब होगा यदि यह `access granted/denied` संदेश प्रदर्शित करता है (केवल जांच करना चाहिए और परिणाम वापस करना चाहिए)। -ये उदाहरण उपसर्गों के सामान्य अर्थ ग्रहण करते हैं। आप और आपकी टीम अन्य अर्थों पर सहमत होने के लिए स्वतंत्र हैं, लेकिन आमतौर पर, वे बहुत भिन्न नहीं होते हैं। किसी भी मामले में, आपको इस बात की पक्की समझ होनी चाहिए कि उपसर्ग का क्या अर्थ है, उपसर्ग का function क्या कर सकता है और क्या नहीं। सभी समान-उपसर्ग फ़ंक्शन को नियमों का पालन करना चाहिए। और टीम को ज्ञान साझा करना चाहिए। +ये उदाहरण उपसर्गों के सामान्य अर्थ ग्रहण करते हैं। आप और आपकी टीम अन्य अर्थों पर सहमत होने के लिए स्वतंत्र हैं, लेकिन आमतौर पर, वे बहुत भिन्न नहीं होते हैं। किसी भी मामले में, आपको इस बात की पक्की समझ होनी चाहिए कि उपसर्ग का क्या अर्थ है, उपसर्ग का function क्या कर सकता है और क्या नहीं। सभी समान-उपसर्ग function को नियमों का पालन करना चाहिए। और टीम को ज्ञान साझा करना चाहिए। ``` ```smart header="Ultrashort function names" -*अक्सर* उपयोग किए जाने वाले फ़ंक्शंस में कभी-कभी अल्ट्रा-शॉर्ट नाम होते हैं। +*अक्सर* उपयोग किए जाने वाले functions में कभी-कभी अल्ट्रा-शॉर्ट नाम होते हैं। उदाहरण के लिए, [jQuery](http://jquery.com) फ्रेमवर्क `$` के साथ एक function को परिभाषित करता है। The [Lodash](http://lodash.com/) library का मुख्य function `_` है। @@ -420,7 +418,7 @@ Functions छोटे होने चाहिए और ठीक एक क एक अलग function न केवल परीक्षण और डीबग करना आसान है - इसका अस्तित्व एक महान comment है! -उदाहरण के लिए, नीचे दिए गए दो कार्यों `showPrimes(n)` की तुलना करें। हर एक `n` तक [अभाज्य संख्याएँ](https://en.wikipedia.org/wiki/Prime_number) आउटपुट करता है। +उदाहरण के लिए, नीचे दिए गए दो functions `showPrimes(n)` की तुलना करें। हर एक `n` तक [अभाज्य संख्याएँ](https://en.wikipedia.org/wiki/Prime_number) आउटपुट करता है। पहला संस्करण एक लेबल का उपयोग करता है: @@ -456,7 +454,7 @@ function isPrime(n) { } ``` -दूसरा संस्करण समझना आसान है, है ना? कोड पीस के बजाय हम क्रिया का एक नाम देखते हैं (`isPrime`)। कभी-कभी लोग ऐसे कोड को _self-describing_ कहते हैं। +दूसरा संस्करण समझना आसान है, है ना? कोड पीस के बजाय हम क्रिया का एक नाम देखते हैं (`isPrime`)। कभी-कभी लोग ऐसे कोड को _स्वयं का वर्णन करना_ कहते हैं। इसलिए, function बनाए जा सकते हैं, भले ही हम उनका पुन: उपयोग करने का इरादा न रखते हों। वे कोड की संरचना करते हैं और इसे पठनीय बनाते हैं। @@ -470,13 +468,13 @@ function name(parameters, delimited, by, comma) { } ``` -- किसी function को दिए गए मान parameters के रूप में उसके local variables में कॉपी किए जाते हैं। +- किसी function को दिए गए मान parameters के रूप में उसके स्थानीय variables में कॉपी किए जाते हैं। - एक function बाहरी variables का इस्तेमाल कर सकता है। लेकिन यह केवल अंदर से बाहर काम करता है। function के बाहर का कोड इसके स्थानीय variables नहीं देखता है। - एक function एक मान वापस कर सकता है। यदि ऐसा नहीं होता है, तो इसका परिणाम `undefined` होता है। -कोड को साफ और समझने में आसान बनाने के लिए, function में मुख्य रूप से local variables और parameter का उपयोग करने की अनुशंसा की जाती है, outer variables नहीं। +कोड को साफ और समझने में आसान बनाने के लिए, function में मुख्य रूप से स्थानीय variables और parameter का उपयोग करने की अनुशंसा की जाती है, बाहरी variables नहीं। -ऐसे function को समझना हमेशा आसान होता है जो पैरामीटर प्राप्त करता है, उनके साथ काम करता है, और किसी ऐसे फ़ंक्शन की तुलना में परिणाम देता है जिसमें कोई पैरामीटर नहीं होता है, लेकिन बाहरी variables को साइड-इफेक्ट के रूप में संशोधित करता है। +ऐसे function को समझना हमेशा आसान होता है जो parameter प्राप्त करता है, उनके साथ काम करता है, और किसी ऐसे function की तुलना में परिणाम देता है जिसमें कोई parameter नहीं होता है, लेकिन बाहरी variables को साइड-इफेक्ट के रूप में संशोधित करता है। Function नामकरण: From 56a438d1bc3326cca33bf4541334a6b812ddda62 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Wed, 22 Sep 2021 00:00:57 +0530 Subject: [PATCH 29/43] Update article.md --- 1-js/02-first-steps/15-function-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 198d0ede3..9ff176a85 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -210,7 +210,7 @@ function showMessage(from, text = anotherFunction()) { ```smart header="Evaluation of default parameters" जावास्क्रिप्ट में, हर बार संबंधित parameter के बिना function को कॉल किए जाने पर एक डिफ़ॉल्ट parameter का मूल्यांकन किया जाता है। -ऊपर दिए गए उदाहरण में, `another function()` को हर बार कॉल किया जाता है जब भी `showMessage()` को `text` parameter के बिना कॉल किया जाता है। +ऊपर दिए गए उदाहरण में, `anotherFunction()` को हर बार कॉल किया जाता है जब भी `showMessage()` को `text` parameter के बिना कॉल किया जाता है। ``` ### वैकल्पिक डिफ़ॉल्ट parameters From 270a3937891e26a09442b485a46a4073f4832701 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Mon, 27 Sep 2021 11:14:08 +0530 Subject: [PATCH 30/43] Update article.md --- 1-js/02-first-steps/16-function-expressions/article.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/16-function-expressions/article.md b/1-js/02-first-steps/16-function-expressions/article.md index a8ccd6c6c..cddc5dab9 100644 --- a/1-js/02-first-steps/16-function-expressions/article.md +++ b/1-js/02-first-steps/16-function-expressions/article.md @@ -1,8 +1,8 @@ -# Function expressions +# Function व्यंजक -In JavaScript, a function is not a "magical language structure", but a special kind of value. +जावास्क्रिप्ट में, एक function "जादुई भाषा संरचना" नहीं है, बल्कि एक विशेष प्रकार का मूल्य है। -The syntax that we used before is called a *Function Declaration*: +हमने पहले जिस सिंटैक्स का उपयोग किया था, उसे *function घोषणा* कहा जाता है: ```js function sayHi() { @@ -10,9 +10,9 @@ function sayHi() { } ``` -There is another syntax for creating a function that is called a *Function Expression*. +function बनाने के लिए एक और सिंटैक्स है जिसे *फंक्शन व्यंजक* कहा जाता है। -It looks like this: +यह इस तरह दीखता है: ```js let sayHi = function() { From ac357ca611b6e9f556cfd4bf07d395220d5d0bb2 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Mon, 27 Sep 2021 11:14:26 +0530 Subject: [PATCH 31/43] Update article.md --- 1-js/02-first-steps/16-function-expressions/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/16-function-expressions/article.md b/1-js/02-first-steps/16-function-expressions/article.md index cddc5dab9..95bb4fa6a 100644 --- a/1-js/02-first-steps/16-function-expressions/article.md +++ b/1-js/02-first-steps/16-function-expressions/article.md @@ -1,6 +1,6 @@ # Function व्यंजक -जावास्क्रिप्ट में, एक function "जादुई भाषा संरचना" नहीं है, बल्कि एक विशेष प्रकार का मूल्य है। +Javascript में, एक function "जादुई भाषा संरचना" नहीं है, बल्कि एक विशेष प्रकार का मूल्य है। हमने पहले जिस सिंटैक्स का उपयोग किया था, उसे *function घोषणा* कहा जाता है: From 0588885715872cbb590f6e1ae1b394cd83beb8e2 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 1 Oct 2021 14:41:53 +0530 Subject: [PATCH 32/43] Update article.md --- .../16-function-expressions/article.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/1-js/02-first-steps/16-function-expressions/article.md b/1-js/02-first-steps/16-function-expressions/article.md index 95bb4fa6a..3898da877 100644 --- a/1-js/02-first-steps/16-function-expressions/article.md +++ b/1-js/02-first-steps/16-function-expressions/article.md @@ -20,11 +20,11 @@ let sayHi = function() { }; ``` -Here, the function is created and assigned to the variable explicitly, like any other value. No matter how the function is defined, it's just a value stored in the variable `sayHi`. +यहां, function को किसी अन्य मान की तरह, स्पष्ट रूप से बनाया गया है और variable को असाइन किया गया है। कोई फर्क नहीं पड़ता कि function को कैसे परिभाषित किया गया है, यह केवल 'sayHi' variable में संग्रहीत एक मान है। -The meaning of these code samples is the same: "create a function and put it into the variable `sayHi`". +इन कोड नमूनों का अर्थ एक ही है: "एक function बनाएं और इसे variable `sayHi` में डालें"। -We can even print out that value using `alert`: +हम `alert` का उपयोग करके उस मूल्य को प्रिंट भी कर सकते हैं: ```js run function sayHi() { @@ -36,15 +36,15 @@ alert( sayHi ); // shows the function code */!* ``` -Please note that the last line does not run the function, because there are no parentheses after `sayHi`. There are programming languages where any mention of a function name causes its execution, but JavaScript is not like that. +कृपया ध्यान दें कि अंतिम पंक्ति function नहीं चलाती है, क्योंकि `sayHi` के बाद कोई कोष्ठक नहीं है। ऐसी प्रोग्रामिंग भाषाएं हैं जहां किसी function नाम का कोई उल्लेख इसके निष्पादन का कारण बनता है, लेकिन Javascript ऐसा नहीं है। -In JavaScript, a function is a value, so we can deal with it as a value. The code above shows its string representation, which is the source code. +Javascript में, एक function एक मान है, इसलिए हम इसे एक मान के रूप में व्यवहार कर सकते हैं। उपरोक्त कोड इसका स्ट्रिंग प्रतिनिधित्व दिखाता है, जो स्रोत कोड है। -Surely, a function is a special value, in the sense that we can call it like `sayHi()`. +निश्चित रूप से, एक function एक विशेष मूल्य है, इस अर्थ में कि हम इसे `sayHi()` की तरह कॉल कर सकते हैं। -But it's still a value. So we can work with it like with other kinds of values. +लेकिन यह फिर भी एक मूल्य है। इसलिए हम इसके साथ अन्य प्रकार के मूल्यों की तरह काम कर सकते हैं। -We can copy a function to another variable: +हम एक function को दूसरे variable में कॉपी कर सकते हैं: ```js run no-beautify function sayHi() { // (1) create From 0af994ef3cc5e5b50b38ae6e45cda9b4e5d9412a Mon Sep 17 00:00:00 2001 From: rskhan167 Date: Thu, 14 Oct 2021 20:13:29 +0530 Subject: [PATCH 33/43] update func exp file --- .../16-function-expressions/article.md | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/1-js/02-first-steps/16-function-expressions/article.md b/1-js/02-first-steps/16-function-expressions/article.md index 3898da877..b0d0dd183 100644 --- a/1-js/02-first-steps/16-function-expressions/article.md +++ b/1-js/02-first-steps/16-function-expressions/article.md @@ -1,4 +1,4 @@ -# Function व्यंजक +# Function एक्सप्रेशन Javascript में, एक function "जादुई भाषा संरचना" नहीं है, बल्कि एक विशेष प्रकार का मूल्य है। @@ -10,7 +10,7 @@ function sayHi() { } ``` -function बनाने के लिए एक और सिंटैक्स है जिसे *फंक्शन व्यंजक* कहा जाता है। +function बनाने के लिए एक और सिंटैक्स है जिसे *function एक्सप्रेशन* कहा जाता है। यह इस तरह दीखता है: @@ -57,13 +57,13 @@ func(); // Hello // (3) run the copy (it works)! sayHi(); // Hello // this still works too (why wouldn't it) ``` -Here's what happens above in detail: +ऊपर विस्तार से यह होता है: -1. The Function Declaration `(1)` creates the function and puts it into the variable named `sayHi`. -2. Line `(2)` copies it into the variable `func`. Please note again: there are no parentheses after `sayHi`. If there were, then `func = sayHi()` would write *the result of the call* `sayHi()` into `func`, not *the function* `sayHi` itself. -3. Now the function can be called as both `sayHi()` and `func()`. +1. Function घोषणा `(1)` function बनाता है और इसे `sayHi` नाम के variable में डालता है। +2. लाइन `(2)` इसे variable `func` में कॉपी करती है। कृपया फिर से ध्यान दें: `sayHi` के बाद कोई कोष्ठक नहीं है। अगर वहाँ होता, तो `func = sayHi()` *कॉल का परिणाम* `sayHi()` को `func` में लिखता, न कि *function* `sayHi` को ही। +3. अब function को `sayHi()` और `func()` दोनों के रूप में कॉल किया जा सकता है। -Note that we could also have used a Function Expression to declare `sayHi`, in the first line: +ध्यान दें कि हम पहली पंक्ति में `sayHi` घोषित करने के लिए एक function एक्सप्रेशन का भी इस्तेमाल कर सकते थे: ```js let sayHi = function() { @@ -74,11 +74,11 @@ let func = sayHi; // ... ``` -Everything would work the same. +सब कुछ वैसा ही काम करेगा। -````smart header="Why is there a semicolon at the end?" -You might wonder, why does Function Expression have a semicolon `;` at the end, but Function Declaration does not: +````smart header="अंत में अर्धविराम क्यों है?" +आपको आश्चर्य हो सकता है कि function एक्सप्रेशन के अंत में अर्धविराम क्यों होता है, लेकिन function डिक्लेरेशन में यह नहीं होता है: ```js function sayHi() { @@ -90,27 +90,27 @@ let sayHi = function() { }*!*;*/!* ``` -The answer is simple: -- There's no need for `;` at the end of code blocks and syntax structures that use them like `if { ... }`, `for { }`, `function f { }` etc. -- A Function Expression is used inside the statement: `let sayHi = ...;`, as a value. It's not a code block, but rather an assignment. The semicolon `;` is recommended at the end of statements, no matter what the value is. So the semicolon here is not related to the Function Expression itself, it just terminates the statement. +उत्तर सीधा है: +- कोड ब्लॉक और सिंटैक्स संरचनाओं के अंत में `;` की कोई आवश्यकता नहीं है जो उनका उपयोग करते हैं जैसे `if {...}`, `के लिए { }`, `फ़ंक्शन f { }` आदि। +- स्टेटमेंट के अंदर एक function एक्सप्रेशन का उपयोग किया जाता है: `let sayHi = ...;`, मान के रूप में। यह एक कोड ब्लॉक नहीं है, बल्कि एक असाइनमेंट है। स्टेटमेंट के अंत में अर्धविराम `;` की सिफारिश की जाती है, भले ही मूल्य कुछ भी हो। तो यहां अर्धविराम function अभिव्यक्ति से संबंधित नहीं है, यह केवल स्टेटमेंट को समाप्त करता है। ```` -## Callback functions +## कॉलबैक functions -Let's look at more examples of passing functions as values and using function expressions. +आइए function को मानों के रूप में पास करने और function एक्सप्रेशन का उपयोग करने के अधिक उदाहरण देखें। -We'll write a function `ask(question, yes, no)` with three parameters: +हम तीन parameters के साथ `ask(question, yes, no)` function लिखेंगे: `question` -: Text of the question +: प्रश्न का पाठ `yes` -: Function to run if the answer is "Yes" +: यदि उत्तर "हां" है तो function चलेगा `no` -: Function to run if the answer is "No" +: यदि उत्तर "नहीं" है तो function चलेगा -The function should ask the `question` and, depending on the user's answer, call `yes()` or `no()`: +Function को `प्रश्न` पूछना चाहिए और, उपयोगकर्ता के उत्तर के आधार पर, `yes()` या `no()` पर कॉल करना चाहिए: ```js run *!* From 50bab0cbcc7050270cb283238b6934d05742bb40 Mon Sep 17 00:00:00 2001 From: rskhan167 Date: Fri, 15 Oct 2021 17:24:31 +0530 Subject: [PATCH 34/43] update function expression file --- .../16-function-expressions/article.md | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/1-js/02-first-steps/16-function-expressions/article.md b/1-js/02-first-steps/16-function-expressions/article.md index b0d0dd183..fdedcb05f 100644 --- a/1-js/02-first-steps/16-function-expressions/article.md +++ b/1-js/02-first-steps/16-function-expressions/article.md @@ -78,7 +78,7 @@ let func = sayHi; ````smart header="अंत में अर्धविराम क्यों है?" -आपको आश्चर्य हो सकता है कि function एक्सप्रेशन के अंत में अर्धविराम क्यों होता है, लेकिन function डिक्लेरेशन में यह नहीं होता है: +आपको आश्चर्य हो सकता है कि function एक्सप्रेशन के अंत में अर्धविराम क्यों होता है, लेकिन function घोषणा में यह नहीं होता है: ```js function sayHi() { @@ -132,13 +132,13 @@ function showCancel() { ask("Do you agree?", showOk, showCancel); ``` -In practice, such functions are quite useful. The major difference between a real-life `ask` and the example above is that real-life functions use more complex ways to interact with the user than a simple `confirm`. In the browser, such function usually draws a nice-looking question window. But that's another story. +व्यावहारिक रूप से, ऐसे function काफी उपयोगी होते हैं। वास्तविक जीवन `ask` और उपरोक्त उदाहरण के बीच मुख्य अंतर यह है कि वास्तविक जीवन के function एक साधारण `confirm` की तुलना में उपयोगकर्ता के साथ बातचीत करने के लिए अधिक जटिल तरीकों का उपयोग करते हैं। ब्राउज़र में, ऐसा function आमतौर पर एक अच्छी दिखने वाली प्रश्न विंडो बनाता है। लेकिन यह एक दूसरी कहानी है। -**The arguments `showOk` and `showCancel` of `ask` are called *callback functions* or just *callbacks*.** +**`ask` के तर्क `showOk` और `showCancel` को *कॉलबैक function* या सिर्फ *कॉलबैक* कहा जाता है।** -The idea is that we pass a function and expect it to be "called back" later if necessary. In our case, `showOk` becomes the callback for "yes" answer, and `showCancel` for "no" answer. +विचार यह है कि हम एक function पास करते हैं और उम्मीद करते हैं कि यदि आवश्यक हो तो इसे बाद में "कॉलबैक किया जाए"। हमारे मामले में, `showOk` "हां" उत्तर के लिए कॉलबैक बन जाता है, और "नहीं" उत्तर के लिए `showCancel` बन जाता है। -We can use Function Expressions to write the same function much shorter: +हम एक ही function को बहुत छोटा लिखने के लिए function एक्सप्रेशंस का उपयोग कर सकते हैं: ```js run no-beautify function ask(question, yes, no) { @@ -155,59 +155,59 @@ ask( */!* ``` -Here, functions are declared right inside the `ask(...)` call. They have no name, and so are called *anonymous*. Such functions are not accessible outside of `ask` (because they are not assigned to variables), but that's just what we want here. +यहां, `ask(...)` कॉल के ठीक अंदर function घोषित किए गए हैं। उनका कोई नाम नहीं है, और इसलिए उन्हें *अनाम* कहा जाता है। इस तरह के function `ask` के बाहर पहुंच योग्य नहीं हैं (क्योंकि वे variable को असाइन नहीं किए गए हैं), लेकिन यह वही है जो हम यहां चाहते हैं। -Such code appears in our scripts very naturally, it's in the spirit of JavaScript. +ऐसा कोड हमारी स्क्रिप्ट में बहुत स्वाभाविक रूप से प्रकट होता है, यह जावास्क्रिप्ट की भावना में है। -```smart header="A function is a value representing an \"action\"" -Regular values like strings or numbers represent the *data*. +```smart header="एक function एक \"क्रिया\" का प्रतिनिधित्व करने वाला मान है" +स्ट्रिंग या संख्या जैसे नियमित मान *डेटा* का प्रतिनिधित्व करते हैं। -A function can be perceived as an *action*. +एक function को एक *क्रिया* के रूप में माना जा सकता है। -We can pass it between variables and run when we want. +हम इसे variables के बीच पास कर सकते हैं और जब चाहें चला सकते हैं। ``` -## Function Expression vs Function Declaration +## Function एक्सप्रेशन बनाम function घोषणा -Let's formulate the key differences between Function Declarations and Expressions. +आइए function घोषणाओं और एक्सप्रेशन के बीच महत्वपूर्ण अंतर तैयार करें। -First, the syntax: how to differentiate between them in the code. +सबसे पहले, सिंटेक्स: कोड में उनके बीच अंतर कैसे करें। -- *Function Declaration:* a function, declared as a separate statement, in the main code flow. +- *Function घोषणा:* एक फ़ंक्शन, जिसे मुख्य कोड प्रवाह में एक अलग स्टेटमेंट के रूप में घोषित किया गया है। ```js - // Function Declaration + // Function घोषणा function sum(a, b) { return a + b; } ``` -- *Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created at the right side of the "assignment expression" `=`: +- *Function एक्सप्रेशन:* एक function, एक एक्सप्रेशन के अंदर या किसी अन्य सिंटेक्स निर्माण के अंदर बनाया गया। यहां, function "असाइनमेंट एक्सप्रेशन" `=` के दाईं ओर बनाया गया है: ```js - // Function Expression + // Function एक्सप्रेशन let sum = function(a, b) { return a + b; }; ``` -The more subtle difference is *when* a function is created by the JavaScript engine. +अधिक सूक्ष्म अंतर यह है कि *जब* JavaScript इंजन द्वारा कोई function बनाया जाता है। -**A Function Expression is created when the execution reaches it and is usable only from that moment.** +**एक function एक्सप्रेशन तब बनाया जाता है जब निष्पादन उस तक पहुँच जाता है और केवल उसी क्षण से प्रयोग करने योग्य होता है।** -Once the execution flow passes to the right side of the assignment `let sum = function…` -- here we go, the function is created and can be used (assigned, called, etc. ) from now on. +एक बार निष्पादन प्रवाह असाइनमेंट के दाईं ओर जाता है `let sum = function…` -- यहां, function बनाया जाता है और अब से इसका उपयोग (असाइन, कॉल, आदि) किया जा सकता है। -Function Declarations are different. +Function घोषणाएं अलग हैं। -**A Function Declaration can be called earlier than it is defined.** +**एक function घोषणा को परिभाषित किए जाने से पहले कॉल किया जा सकता है।** -For example, a global Function Declaration is visible in the whole script, no matter where it is. +उदाहरण के लिए, एक वैश्विक function घोषणा पूरी स्क्रिप्ट में दिखाई देती है, चाहे वह कहीं भी हो। -That's due to internal algorithms. When JavaScript prepares to run the script, it first looks for global Function Declarations in it and creates the functions. We can think of it as an "initialization stage". +यह आंतरिक एल्गोरिदम के कारण है। जब JavaScript स्क्रिप्ट को चलाने के लिए तैयार होता है, तो यह सबसे पहले इसमें ग्लोबल function घोषणा की तलाश करता है और function बनाता है। हम इसे "आरंभीकरण चरण" के रूप में सोच सकते हैं। -And after all Function Declarations are processed, the code is executed. So it has access to these functions. +और सभी function घोषणाओं को संसाधित करने के बाद, कोड निष्पादित किया जाता है। तो इसे इन functions का एक्सेस उपलब्ध होता है। -For example, this works: +उदाहरण के लिए, यह काम करता है: ```js run refresh untrusted *!* @@ -219,9 +219,9 @@ function sayHi(name) { } ``` -The Function Declaration `sayHi` is created when JavaScript is preparing to start the script and is visible everywhere in it. +Function घोषणा `sayHi` तब बनाया जाता है जब JavaScript स्क्रिप्ट शुरू करने की तैयारी कर रहा होता है और इसमें हर जगह दिखाई देता है। -...If it were a Function Expression, then it wouldn't work: +...यदि यह एक function एक्सप्रेशन होता, तो यह काम नहीं करता: ```js run refresh untrusted *!* @@ -233,20 +233,20 @@ let sayHi = function(name) { // (*) no magic any more }; ``` -Function Expressions are created when the execution reaches them. That would happen only in the line `(*)`. Too late. +जब निष्पादन उन तक पहुंचता है तो function एक्सप्रेशन बनाए जाते हैं। यह केवल `(*)` लाइन में होगा। बहुत देर। -Another special feature of Function Declarations is their block scope. +Function घोषणा की एक और खास विशेषता उनका ब्लॉक स्कोप है। -**In strict mode, when a Function Declaration is within a code block, it's visible everywhere inside that block. But not outside of it.** +**सख्त मोड में, जब कोई function घोषणा कोड ब्लॉक के भीतर होती है, तो यह उस ब्लॉक के अंदर हर जगह दिखाई देती है। लेकिन इसके बाहर नहीं।** -For instance, let's imagine that we need to declare a function `welcome()` depending on the `age` variable that we get during runtime. And then we plan to use it some time later. +उदाहरण के लिए, आइए कल्पना करें कि हमें रनटाइम के दौरान प्राप्त होने वाले `age` चर के आधार पर एक function `welcome()` घोषित करने की आवश्यकता है। और फिर हम इसे कुछ समय बाद उपयोग करने की योजना बनाते हैं। -If we use Function Declaration, it won't work as intended: +यदि हम function घोषणा का उपयोग करते हैं, तो यह इरादा के अनुसार काम नहीं करेगा: ```js run let age = prompt("What is your age?", 18); -// conditionally declare a function +// सशर्त रूप से एक function घोषित करें if (age < 18) { function welcome() { @@ -261,30 +261,30 @@ if (age < 18) { } -// ...use it later +// ...बाद में इसका इस्तेमाल करें *!* -welcome(); // Error: welcome is not defined +welcome(); // त्रुटि: स्वागत परिभाषित नहीं है */!* ``` -That's because a Function Declaration is only visible inside the code block in which it resides. +ऐसा इसलिए है क्योंकि function घोषणा केवल उस कोड ब्लॉक के अंदर दिखाई देती है जिसमें वह रहता है। -Here's another example: +यहाँ एक और उदाहरण है: ```js run -let age = 16; // take 16 as an example +let age = 16; // उदाहरण के तौर पर 16 लें if (age < 18) { *!* - welcome(); // \ (runs) + welcome(); // \ (चल रहा है।) */!* // | function welcome() { // | - alert("Hello!"); // | Function Declaration is available - } // | everywhere in the block where it's declared + alert("Hello!"); // | Function घोषणा उपलब्ध है + } // | ब्लॉक में हर जगह जहां इसे घोषित किया गया है // | *!* - welcome(); // / (runs) + welcome(); // / (चल रहा है।) */!* } else { @@ -294,19 +294,19 @@ if (age < 18) { } } -// Here we're out of curly braces, -// so we can not see Function Declarations made inside of them. +// यहाँ हम घुंघराले ब्रेसिज़ से बाहर हैं, +// इसलिए हम उनके अंदर किए गए function घोषणा को नहीं देख सकते हैं। *!* -welcome(); // Error: welcome is not defined +welcome(); // त्रुटि: स्वागत परिभाषित नहीं है */!* ``` -What can we do to make `welcome` visible outside of `if`? +हम `if` के बाहर `welcome` को दृश्यमान बनाने के लिए क्या कर सकते हैं? -The correct approach would be to use a Function Expression and assign `welcome` to the variable that is declared outside of `if` and has the proper visibility. +सही तरीका यह होगा कि एक function एक्सप्रेशन का उपयोग करें और `welcome` को variable में असाइन करें जिसे `if` के बाहर घोषित किया गया है और इसकी उचित दृश्यता है। -This code works as intended: +यह कोड इरादा के अनुसार काम करता है: ```js run let age = prompt("What is your age?", 18); @@ -328,11 +328,11 @@ if (age < 18) { } *!* -welcome(); // ok now +welcome(); // अब ठीक है */!* ``` -Or we could simplify it even further using a question mark operator `?`: +या हम एक प्रश्न चिह्न ऑपरेटर `?` का उपयोग करके इसे और भी सरल बना सकते हैं: ```js run let age = prompt("What is your age?", 18); @@ -342,27 +342,27 @@ let welcome = (age < 18) ? function() { alert("Greetings!"); }; *!* -welcome(); // ok now +welcome(); // अब ठीक है */!* ``` -```smart header="When to choose Function Declaration versus Function Expression?" -As a rule of thumb, when we need to declare a function, the first to consider is Function Declaration syntax. It gives more freedom in how to organize our code, because we can call such functions before they are declared. +```smart header="function घोषणा बनाम function एक्सप्रेशन कब चुनें?" +एक नियम के रूप में, जब हमें किसी function को घोषित करने की आवश्यकता होती है, तो सबसे पहले विचार करने के लिए function घोषणा सिंटैक्स होता है। यह आपके कोड को व्यवस्थित करने के तरीके में अधिक स्वतंत्रता देता है, क्योंकि हम ऐसे function को घोषित होने से पहले कॉल कर सकते हैं। -That's also better for readability, as it's easier to look up `function f(…) {…}` in the code than `let f = function(…) {…};`. Function Declarations are more "eye-catching". +यह पठनीयता के लिए भी बेहतर है, क्योंकि `let f = function(…) {…};` की तुलना में कोड में `function f(…) {…}` को देखना आसान है। Function घोषणाएं अधिक "आकर्षक" हैं। -...But if a Function Declaration does not suit us for some reason, or we need a conditional declaration (we've just seen an example), then Function Expression should be used. +...लेकिन अगर किसी कारण से कोई function घोषणा हमें सूट नहीं करता है, या हमें कंडीशनल घोषणा की जरूरत है (हमने अभी एक उदाहरण देखा है), तो function एक्सप्रेशन का इस्तेमाल किया जाना चाहिए। ``` -## Summary +## सारांश -- Functions are values. They can be assigned, copied or declared in any place of the code. -- If the function is declared as a separate statement in the main code flow, that's called a "Function Declaration". -- If the function is created as a part of an expression, it's called a "Function Expression". -- Function Declarations are processed before the code block is executed. They are visible everywhere in the block. -- Function Expressions are created when the execution flow reaches them. +- Functions मूल्य हैं। उन्हें कोड के किसी भी स्थान पर असाइन, कॉपी या घोषित किया जा सकता है। +- यदि function को मुख्य कोड प्रवाह में एक अलग स्टेटमेंट के रूप में घोषित किया जाता है, तो इसे "function घोषणा" कहा जाता है। +- यदि function एक एक्सप्रेशन के हिस्से के रूप में बनाया गया है, तो इसे "function एक्सप्रेशन" कहा जाता है। +- कोड ब्लॉक निष्पादित होने से पहले function घोषणाओं को संसाधित किया जाता है। वे ब्लॉक में हर जगह दिखाई दे रहे हैं। +- Function एक्सप्रेशन तब बनते हैं जब निष्पादन प्रवाह उन तक पहुंचता है। -In most cases when we need to declare a function, a Function Declaration is preferable, because it is visible prior to the declaration itself. That gives us more flexibility in code organization, and is usually more readable. +ज्यादातर मामलों में जब हमें किसी function को घोषित करने की आवश्यकता होती है, तो function घोषणा बेहतर होती है, क्योंकि यह घोषणा से पहले ही दिखाई देती है। यह हमें कोड संगठन में अधिक लचीलापन देता है, और आमतौर पर अधिक पठनीय होता है। -So we should use a Function Expression only when a Function Declaration is not fit for the task. We've seen a couple of examples of that in this chapter, and will see more in the future. +इसलिए हमें function एक्सप्रेशन का उपयोग तभी करना चाहिए जब कोई function घोषणा कार्य के लिए उपयुक्त न हो। हमने इस अध्याय में इसके कुछ उदाहरण देखे हैं, और भविष्य में और देखेंगे। From 582c9c2a9b46d0ae99aaee3c809917c557888bc6 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:26:49 +0530 Subject: [PATCH 35/43] Update solution.md --- .../15-function-basics/1-if-else-required/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md b/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md index 7e1a36a09..5bbf5a908 100644 --- a/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md +++ b/1-js/02-first-steps/15-function-basics/1-if-else-required/solution.md @@ -1 +1 @@ -कोई फर्क नहीं। +No difference. From ce01f1205547be3fbcf381331545d385268d4af6 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:27:09 +0530 Subject: [PATCH 36/43] Update task.md --- .../15-function-basics/1-if-else-required/task.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md b/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md index 3678b4034..4f69a5c8c 100644 --- a/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md +++ b/1-js/02-first-steps/15-function-basics/1-if-else-required/task.md @@ -2,11 +2,11 @@ importance: 4 --- -# क्या "else" आवश्यक है? +# Is "else" required? -यदि `age` parameter `18` से अधिक है, तो निम्नलिखित function `true` लौटाता है। +The following function returns `true` if the parameter `age` is greater than `18`. -अन्यथा, यह एक पुष्टिकरण मांगता है और अपना परिणाम देता है: +Otherwise it asks for a confirmation and returns its result: ```js function checkAge(age) { @@ -15,13 +15,13 @@ function checkAge(age) { *!* } else { // ... - return confirm('क्या माता-पिता ने आपको अनुमति दी थी?'); + return confirm('Did parents allow you?'); } */!* } ``` -यदि `else` हटा दिया जाता है तो क्या function अलग तरह से काम करेगा? +Will the function work differently if `else` is removed? ```js function checkAge(age) { @@ -30,9 +30,9 @@ function checkAge(age) { } *!* // ... - return confirm('क्या माता-पिता ने आपको अनुमति दी थी?'); + return confirm('Did parents allow you?'); */!* } ``` -क्या इन दोनों रूपों के व्यवहार में कोई अंतर है? +Is there any difference in the behavior of these two variants? From f218a78a17836b8548039cbbaa31b3f15f06ed7c Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:27:33 +0530 Subject: [PATCH 37/43] Update solution.md --- .../2-rewrite-function-question-or/solution.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md index c212e65b0..c8ee9618f 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md @@ -1,17 +1,17 @@ -प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?`: +Using a question mark operator `'?'`: ```js function checkAge(age) { - return (age > 18) ? true : confirm('क्या माता-पिता ने आपको अनुमति दी थी?'); + return (age > 18) ? true : confirm('Did parents allow you?'); } ``` -OR ऑपरेटर का उपयोग करते हुए `||` (सबसे छोटा संस्करण) +Using OR `||` (the shortest variant): ```js function checkAge(age) { - return (age > 18) || confirm('क्या माता-पिता ने आपको अनुमति दी थ?'); + return (age > 18) || confirm('Did parents allow you?'); } ``` -ध्यान दें कि यहां `age > 18` के आसपास के कोष्ठकों की आवश्यकता नहीं है। वे बेहतर पठनीयता के लिए मौजूद हैं। +Note that the parentheses around `age > 18` are not required here. They exist for better readabilty. From b47dc453be0199ddb76d237ab4f620d72b916c09 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:27:54 +0530 Subject: [PATCH 38/43] Update task.md --- .../2-rewrite-function-question-or/task.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md index 59d0fc840..46da079c0 100644 --- a/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/task.md @@ -2,25 +2,25 @@ importance: 4 --- -# '?' या '||' का उपयोग करके function को फिर से लिखें| +# Rewrite the function using '?' or '||' -यदि `age` parameter `18` से अधिक है, तो निम्नलिखित function `true` लौटाता है। +The following function returns `true` if the parameter `age` is greater than `18`. -अन्यथा, यह एक पुष्टिकरण मांगता है और अपना परिणाम देता है: +Otherwise it asks for a confirmation and returns its result. ```js function checkAge(age) { if (age > 18) { return true; } else { - return confirm("क्या माता-पिता ने आपको अनुमति दी थी?"); + return confirm('Did parents allow you?'); } } ``` -इस function को फिर से लिखें, लेकिन बिना `if` के, एक पंक्ति में। +Rewrite it, to perform the same, but without `if`, in a single line. -`checkAge` के दो प्रकार बनाएं: +Make two variants of `checkAge`: -1. प्रश्न चिह्न ऑपरेटर का उपयोग करते हुए `?` -2. OR ऑपरेटर का उपयोग करते हुए `||` +1. Using a question mark operator `?` +2. Using OR `||` From 3758c9acfbfaf995c3b256c030671914d3ade29a Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:28:16 +0530 Subject: [PATCH 39/43] Update solution.md --- 1-js/02-first-steps/15-function-basics/3-min/solution.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/solution.md b/1-js/02-first-steps/15-function-basics/3-min/solution.md index e3f1c0d47..a8099da0c 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/solution.md +++ b/1-js/02-first-steps/15-function-basics/3-min/solution.md @@ -1,4 +1,4 @@ -`if` का उपयोग करके एक हल: +A solution using `if`: ```js function min(a, b) { @@ -10,7 +10,7 @@ function min(a, b) { } ``` -प्रश्न चिह्न ऑपरेटर `'?'` के साथ एक हल: +A solution with a question mark operator `'?'`: ```js function min(a, b) { @@ -18,4 +18,4 @@ function min(a, b) { } ``` -नोट: समानता `a == b` के मामले में यह मायने नहीं रखता कि क्या लौटाया जाए। +P.S. In the case of an equality `a == b` it does not matter what to return. From fadc14c4473460777b3e8d2d317a1d9e519b208c Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:28:45 +0530 Subject: [PATCH 40/43] Update task.md --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index 56af1f434..b8bee1341 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -4,9 +4,9 @@ importance: 1 # Function min(a, b) -एक फ़ंक्शन लिखें `min(a,b)` जो `a` और `b` नंबर में से जो सबसे छोटा है उसको लौटाता हो। +Write a function `min(a,b)` which returns the least of two numbers `a` and `b`. -उदाहरण के लिए: +For instance: ```js min(2, 5) == 2 From 8b453a8cf87c843b443cc971a59029852456c218 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:32:30 +0530 Subject: [PATCH 41/43] Update task.md --- 1-js/02-first-steps/15-function-basics/4-pow/task.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/4-pow/task.md b/1-js/02-first-steps/15-function-basics/4-pow/task.md index af06008b4..f569320c7 100644 --- a/1-js/02-first-steps/15-function-basics/4-pow/task.md +++ b/1-js/02-first-steps/15-function-basics/4-pow/task.md @@ -4,7 +4,7 @@ importance: 4 # Function pow(x,n) -एक फ़ंक्शन लिखें `pow(x,n)` जो `x` को `n` की घात में लौटाता है। या, दूसरे शब्दों में, `x` को अपने आप से `n` बार गुणा करता है और परिणाम देता है। +Write a function `pow(x,n)` that returns `x` in power `n`. Or, in other words, multiplies `x` by itself `n` times and returns the result. ```js pow(3, 2) = 3 * 3 = 9 @@ -12,8 +12,8 @@ pow(3, 3) = 3 * 3 * 3 = 27 pow(1, 100) = 1 * 1 * ...* 1 = 1 ``` -एक वेब पेज बनाएं जो `x` और `n` के लिए prompt करता है, और फिर `pow(x,n)` का परिणाम दिखाता है। +Create a web-page that prompts for `x` and `n`, and then shows the result of `pow(x,n)`. [demo] -नोट: इस टास्क में function को केवल `n` के प्राकृतिक मानों को स्वीकार करना चाहिए: `1` से ऊपर के पूर्णांक। +P.S. In this task the function should support only natural values of `n`: integers up from `1`. From c3554edb7adafd62124c25e220a8718f4e950e88 Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:33:05 +0530 Subject: [PATCH 42/43] Update article.md --- .../15-function-basics/article.md | 259 +++++++++--------- 1 file changed, 131 insertions(+), 128 deletions(-) diff --git a/1-js/02-first-steps/15-function-basics/article.md b/1-js/02-first-steps/15-function-basics/article.md index 9ff176a85..b12d0b9e7 100644 --- a/1-js/02-first-steps/15-function-basics/article.md +++ b/1-js/02-first-steps/15-function-basics/article.md @@ -1,26 +1,26 @@ # Functions -अक्सर हमें स्क्रिप्ट के कई स्थानों पर इसी तरह की क्रिया करने की आवश्यकता होती है। +Quite often we need to perform a similar action in many places of the script. -उदाहरण के लिए, हमें एक अच्छा दिखने वाला संदेश दिखाना चाहिए जब कोई आगंतुक लॉग इन करता है, लॉग आउट करता है। +For example, we need to show a nice-looking message when a visitor logs in, logs out and maybe somewhere else. -Functions प्रोग्राम के मुख्य "बिल्डिंग ब्लॉक्स" हैं। वे बिना दोहराव के कोड को कई बार कॉल करने की अनुमति देते हैं। +Functions are the main "building blocks" of the program. They allow the code to be called many times without repetition. -हम पहले से ही बिल्ट-इन function के उदाहरण देख चुके हैं, जैसे `alert(message)`, `prompt(message, default)` और `confirm(question)`। लेकिन हम अपने स्वयं के functions भी बना सकते हैं। +We've already seen examples of built-in functions, like `alert(message)`, `prompt(message, default)` and `confirm(question)`. But we can create functions of our own as well. -## Function घोषणा +## Function Declaration -function बनाने के लिए हम एक _function घोषणा_ का उपयोग कर सकते हैं। +To create a function we can use a *function declaration*. -यह इस तरह दिखता है: +It looks like this: ```js function showMessage() { - alert( "सभी को नमस्कार!" ); + alert( 'Hello everyone!' ); } ``` -`function` कीवर्ड पहले जाता है, फिर _function का नाम_ जाता है, फिर कोष्ठक के बीच _parameters_ की एक सूची (उपरोक्त उदाहरण में खाली) और अंत में function का कोड, जिसे "function बॉडी" भी कहा जाता है, घुंघराले ब्रेसिज़ के बीच। +The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (comma-separated, empty in the example above) and finally the code of the function, also named "the function body", between curly braces. ```js function name(parameters) { @@ -28,13 +28,13 @@ function name(parameters) { } ``` -हमारे नए function को इसके नाम से बुलाया जा सकता है: `showMessage()`। +Our new function can be called by its name: `showMessage()`. -उदाहरण के लिए: +For instance: ```js run function showMessage() { - alert( 'सभी को नमस्कार!' ); + alert( 'Hello everyone!' ); } *!* @@ -43,103 +43,103 @@ showMessage(); */!* ``` -`showMessage()` कॉल करने से function के कोड को निष्पादित करता है। यहां हम संदेश को दो बार देखेंगे। +The call `showMessage()` executes the code of the function. Here we will see the message two times. -यह उदाहरण स्पष्ट रूप से function के मुख्य उद्देश्यों में से एक को प्रदर्शित करता है: कोड आवृत्ति से बचने के लिए। +This example clearly demonstrates one of the main purposes of functions: to avoid code duplication. -यदि हमें कभी भी संदेश या उसके दिखाए जाने के तरीके को बदलने की आवश्यकता होती है, तो यह कोड को एक ही स्थान पर संशोधित करने के लिए पर्याप्त है: वह function जो इसे आउटपुट करता है। +If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it. -## लोकल variables +## Local variables -किसी function के अंदर घोषित एक variable केवल उस function के अंदर ही दिखाई देता है। +A variable declared inside a function is only visible inside that function. -उदाहरण के लिए: +For example: ```js run function showMessage() { *!* - let message = "हैलो, मैं जावास्क्रिप्ट हूँ!"; // local variable + let message = "Hello, I'm JavaScript!"; // local variable */!* alert( message ); } -showMessage(); // हैलो, मैं जावास्क्रिप्ट हूँ! +showMessage(); // Hello, I'm JavaScript! -alert( message ); // <-- Error! variable function के लिए स्थानीय है +alert( message ); // <-- Error! The variable is local to the function ``` -## बाहरी variables +## Outer variables -एक function बाहरी variable को भी एक्सेस कर सकता है, उदाहरण के लिए: +A function can access an outer variable as well, for example: ```js run no-beautify let *!*userName*/!* = 'John'; function showMessage() { - let message = 'नमस्ते, ' + *!*userName*/!*; + let message = 'Hello, ' + *!*userName*/!*; alert(message); } -showMessage(); // नमस्ते, John +showMessage(); // Hello, John ``` -function के पास बाहरी variable तक पूर्ण पहुंच है। यह इसे बदल भी कर सकता है। +The function has full access to the outer variable. It can modify it as well. -उदाहरण के लिए: +For instance: ```js run let *!*userName*/!* = 'John'; function showMessage() { - *!*userName*/!* = "Bob"; // (1) बाहरी variable बदल दिया + *!*userName*/!* = "Bob"; // (1) changed the outer variable let message = 'Hello, ' + *!*userName*/!*; alert(message); } -alert( userName ); // *!*John*/!* function कॉल से पहले +alert( userName ); // *!*John*/!* before the function call showMessage(); -alert( userName ); // *!*Bob*/!*, मान function द्वारा संशोधित किया गया था +alert( userName ); // *!*Bob*/!*, the value was modified by the function ``` -बाहरी variable का उपयोग केवल तभी किया जाता है जब कोई लोकल न हो। +The outer variable is only used if there's no local one. -यदि function के अंदर एक ही नामित variable घोषित किया जाता है तो यह बाहरी वाले variable को अनदेखा कर देता है। उदाहरण के लिए, नीचे दिए गए कोड में function लोकल `userName` का उपयोग करता है। बाहरी को अनदेखा किया जाता है: +If a same-named variable is declared inside the function then it *shadows* the outer one. For instance, in the code below the function uses the local `userName`. The outer one is ignored: ```js run let userName = 'John'; function showMessage() { *!* - let userName = "Bob"; // एक local variable घोषित करें + let userName = "Bob"; // declare a local variable */!* let message = 'Hello, ' + userName; // *!*Bob*/!* alert(message); } -// function अपना स्वयं का userName बनाएगा और उसका उपयोग करेगा +// the function will create and use its own userName showMessage(); -alert( userName ); // *!*John*/!*, अपरिवर्तित, function बाहरी variable का उपयोग नहीं करता है +alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable ``` ```smart header="Global variables" -किसी function के बाहर घोषित variables, जैसे उपरोक्त कोड में बाहरी `userName`, *ग्लोबल* कहलाते हैं। +Variables declared outside of any function, such as the outer `userName` in the code above, are called *global*. -ग्लोबल variables किसी भी function से दिखाई देते हैं (जब तक कि लोकल द्वारा छिपा न हो)। +Global variables are visible from any function (unless shadowed by locals). -ग्लोबल variables के उपयोग को कम करना अच्छा अभ्यास है। आधुनिक कोड में कुछ या कोई ग्लोबल्स नहीं हैं। अधिकांश variable अपने functions में रहते हैं। हालांकि कभी-कभी, वे प्रोजेक्ट-स्तरीय डेटा संग्रहीत करने के लिए उपयोगी हो सकते हैं। +It's a good practice to minimize the use of global variables. Modern code has few or no globals. Most variables reside in their functions. Sometimes though, they can be useful to store project-level data. ``` ## Parameters -हम Parameters (जिसे _function arguments_ भी कहा जाता है) का उपयोग करके function को मनमाना डेटा पास कर सकते हैं। +We can pass arbitrary data to functions using parameters (also called *function arguments*) . -नीचे दिए गए उदाहरण में, function के दो parameters हैं: `from` और `text`। +In the example below, the function has two parameters: `from` and `text`. ```js run function showMessage(*!*from, text*/!*) { // arguments: from, text @@ -152,9 +152,10 @@ showMessage('Ann', "What's up?"); // Ann: What's up? (**) */!* ``` -जब function को लाइनों में कॉल किया जाता है `(*)` और `(**)`, तो दिए गए मानों को लोकल variables में कॉपी किया जाता है `from` और `text`। फिर function उनका उपयोग करता है। +When the function is called in lines `(*)` and `(**)`, the given values are copied to local variables `from` and `text`. Then the function uses them. + +Here's one more example: we have a variable `from` and pass it to the function. Please note: the function changes `from`, but the change is not seen outside, because a function always gets a copy of the value: -यहां एक और उदाहरण दिया गया है: हमारे पास एक variable `from` है और इसे function में पास करें। कृपया ध्यान दें: function `from` को बदलता है, लेकिन परिवर्तन बाहर नहीं देखा जाता है, क्योंकि function को हमेशा मूल्य की एक प्रति प्राप्त होती है: ```js run function showMessage(from, text) { @@ -174,19 +175,19 @@ showMessage(from, "Hello"); // *Ann*: Hello alert( from ); // Ann ``` -## डिफॉल्ट वैल्यूज +## Default values -यदि कोई parameter प्रदान नहीं किया जाता है, तो उसका मान `undefined` हो जाता है। +If a parameter is not provided, then its value becomes `undefined`. -उदाहरण के लिए, उपरोक्त function `showMessage(from, text)` को एक argument के साथ बुलाया जा सकता है: +For instance, the aforementioned function `showMessage(from, text)` can be called with a single argument: ```js showMessage("Ann"); ``` -यह कोई एरर नहीं है। ऐसी कॉल `"*Ann*: undefined"` आउटपुट करेगी। कोई `text` नहीं है, इसलिए यह माना जाता है कि `text === undefined`। +That's not an error. Such a call would output `"*Ann*: undefined"`. There's no `text`, so it's assumed that `text === undefined`. -यदि हम इस मामले में "डिफ़ॉल्ट" `text` का उपयोग करना चाहते हैं, तो हम इसे `=` के बाद उल्लिखत कर सकते हैं: +If we want to use a "default" `text` in this case, then we can specify it after `=`: ```js run function showMessage(from, *!*text = "no text given"*/!*) { @@ -196,9 +197,9 @@ function showMessage(from, *!*text = "no text given"*/!*) { showMessage("Ann"); // Ann: no text given ``` -अब यदि `text` parameter नहीं देना गया हो, तो उसे `"no text given"` मान मिलेगा। +Now if the `text` parameter is not passed, it will get the value `"no text given"` -यहां `"no text given"` एक स्ट्रिंग है, लेकिन यह एक अधिक जटिल अभिव्यक्ति हो सकती है, जिसका केवल मूल्यांकन किया जाता है और parameter गायब होने पर असाइन किया जाता है। तो, यह भी संभव है: +Here `"no text given"` is a string, but it can be a more complex expression, which is only evaluated and assigned if the parameter is missing. So, this is also possible: ```js run function showMessage(from, text = anotherFunction()) { @@ -208,45 +209,45 @@ function showMessage(from, text = anotherFunction()) { ``` ```smart header="Evaluation of default parameters" -जावास्क्रिप्ट में, हर बार संबंधित parameter के बिना function को कॉल किए जाने पर एक डिफ़ॉल्ट parameter का मूल्यांकन किया जाता है। +In JavaScript, a default parameter is evaluated every time the function is called without the respective parameter. -ऊपर दिए गए उदाहरण में, `anotherFunction()` को हर बार कॉल किया जाता है जब भी `showMessage()` को `text` parameter के बिना कॉल किया जाता है। +In the example above, `anotherFunction()` is called every time `showMessage()` is called without the `text` parameter. ``` -### वैकल्पिक डिफ़ॉल्ट parameters +### Alternative default parameters -कभी-कभी function घोषणा में parameter के लिए डिफ़ॉल्ट मान सेट करना समझ में आता है, लेकिन बाद के चरण में, इसके निष्पादन के दौरान भी सेट किया जाता है। +Sometimes it makes sense to set default values for parameters not in the function declaration, but at a later stage, during its execution. -छोड़े गए parameter की जांच करने के लिए, हम इसकी तुलना `undefined` से कर सकते हैं: +To check for an omitted parameter, we can compare it with `undefined`: ```js run function showMessage(text) { *!* if (text === undefined) { - text = 'खाली संदेश'; + text = 'empty message'; } */!* alert(text); } -showMessage(); // खाली संदेश +showMessage(); // empty message ``` -...या हम `||` ऑपरेटर का उपयोग कर सकते हैं: +...Or we could use the `||` operator: ```js -// यदि टेक्स्ट parameter छोड़ा गया है या "" पास किया गया है, तो इसे 'empty' पर सेट करें +// if text parameter is omitted or "" is passed, set it to 'empty' function showMessage(text) { text = text || 'empty'; ... } ``` -आधुनिक जावास्क्रिप्ट इंजन [nullish coalescing operator](info:nullish-coalescing-operator) `??` को सपोर्ट करती है| यह तब बेहतर होता है जब `0` जैसे झूठे मूल्यों को नियमित माना जाता है: +Modern JavaScript engines support the [nullish coalescing operator](info:nullish-coalescing-operator) `??`, it's better when falsy values, such as `0`, are considered regular: ```js run -// यदि कोई "count" parameter नहीं है, तो "unknown" दिखाएं +// if there's no "count" parameter, show "unknown" function showCount(count) { alert(count ?? "unknown"); } @@ -256,11 +257,11 @@ showCount(null); // unknown showCount(); // unknown ``` -## एक मान लौटाना +## Returning a value -एक function परिणाम के रूप में एक मान वापस कॉलिंग कोड में लौटा सकता है। +A function can return a value back into the calling code as the result. -सबसे सरल उदाहरण एक ऐसा function होगा जो दो मानों का योग करता है: +The simplest example would be a function that sums two values: ```js run no-beautify function sum(a, b) { @@ -271,9 +272,9 @@ let result = sum(1, 2); alert( result ); // 3 ``` -निर्देश `return` function के किसी भी स्थान पर हो सकता है। जब निष्पादन उस तक पहुंच जाता है, तो function बंद हो जाता है, और मान कॉलिंग कोड पर वापस आ जाता है (उपरोक्त `result` को सौंपा गया) +The directive `return` can be in any place of the function. When the execution reaches it, the function stops, and the value is returned to the calling code (assigned to `result` above). -एक function में `return` की कई घटनाएं हो सकती हैं। उदाहरण के लिए: +There may be many occurrences of `return` in a single function. For instance: ```js run function checkAge(age) { @@ -283,23 +284,23 @@ function checkAge(age) { */!* } else { *!* - return confirm('क्या आपके पास अपने माता-पिता की अनुमति है?'); + return confirm('Do you have permission from your parents?'); */!* } } -let age = prompt('आपकी उम्र क्या है?', 18); +let age = prompt('How old are you?', 18); if ( checkAge(age) ) { - alert( 'प्रवेश करने की अनुमति है' ); + alert( 'Access granted' ); } else { - alert( 'पहुंच अस्वीकृत' ); + alert( 'Access denied' ); } ``` -बिना मूल्य के `return` का उपयोग करना संभव है। यह function को तुरंत बाहर निकलने का कारण बनता है। +It is possible to use `return` without a value. That causes the function to exit immediately. -उदाहरण के लिए: +For example: ```js function showMovie(age) { @@ -309,22 +310,23 @@ function showMovie(age) { */!* } - alert( "आपको फिल्म दिखा रहा है" ); // (*) + alert( "Showing you the movie" ); // (*) // ... } ``` -ऊपर दिए गए कोड में, अगर `checkAge(age)` `false` लौटाता है, तो `showMovie` `alert` पर आगे नहीं बढ़ेगा। +In the code above, if `checkAge(age)` returns `false`, then `showMovie` won't proceed to the `alert`. -````smart header="A function with an empty `return`or without it returns`undefined`" If a function does not return a value, it is the same as if it returns `undefined`: +````smart header="A function with an empty `return` or without it returns `undefined`" +If a function does not return a value, it is the same as if it returns `undefined`: ```js run -function doNothing() { /* खाली */ } +function doNothing() { /* empty */ } alert( doNothing() === undefined ); // true ``` -एक खाली `return` भी `return undefined` जैसा ही है: +An empty `return` is also the same as `return undefined`: ```js run function doNothing() { @@ -336,22 +338,22 @@ alert( doNothing() === undefined ); // true ```` ````warn header="Never add a newline between `return` and the value" -`return` में एक लंबी अभिव्यक्ति के लिए, इसे एक अलग लाइन पर रखना आकर्षक हो सकता है, जैसे: +For a long expression in `return`, it might be tempting to put it on a separate line, like this: ```js return (some + long + expression + or + whatever * f(a) + f(b)) ``` -यह काम नहीं करता है, क्योंकि `return` के बाद जावास्क्रिप्ट सेमीकोलन लगा देता है। यह उसी तरह काम करेगा: +That doesn't work, because JavaScript assumes a semicolon after `return`. That'll work the same as: ```js return*!*;*/!* (some + long + expression + or + whatever * f(a) + f(b)) ``` -तो, यह प्रभावी रूप से एक खाली रिटर्न बन जाता है। +So, it effectively becomes an empty return. -यदि हम चाहते हैं कि लौटाए गए एक्सप्रेशन को कई लाइनों में लपेटा जाए, तो हमें इसे उसी लाइन से शुरू करना चाहिए जैसे `return`। या कम से कम उद्घाटन कोष्ठक इस प्रकार रखें: +If we want the returned expression to wrap across multiple lines, we should start it at the same line as `return`. Or at least put the opening parentheses there as follows: ```js return ( @@ -360,81 +362,82 @@ return ( whatever * f(a) + f(b) ) ``` -और यह वैसे ही काम करेगा जैसा हम उम्मीद करते हैं। +And it will work just as we expect it to. ```` -## Function का नामकरण [#function-naming] +## Naming a function [#function-naming] -Functions क्रिया हैं। तो उनका नाम आमतौर पर एक क्रिया है। यह संक्षिप्त होना चाहिए, यथासंभव सटीक होना चाहिए और यह वर्णन करना चाहिए कि function क्या करता है, ताकि कोड पढ़ने वाले व्यक्ति को यह संकेत मिल सके कि function क्या करता है। +Functions are actions. So their name is usually a verb. It should be brief, as accurate as possible and describe what the function does, so that someone reading the code gets an indication of what the function does. -क्रिया को अस्पष्ट रूप से वर्णित करने वाले मौखिक उपसर्ग के साथ function प्रारंभ करना एक व्यापक प्रथा है। उपसर्गों के अर्थ पर टीम के भीतर एक समझौता होना चाहिए। +It is a widespread practice to start a function with a verbal prefix which vaguely describes the action. There must be an agreement within the team on the meaning of the prefixes. -उदाहरण के लिए, `"show"` से शुरू होने वाले function आमतौर पर कुछ दिखाते हैं। +For instance, functions that start with `"show"` usually show something. -Function की शुरुआत... +Function starting with... -- `"get…"` -- एक मूल्य वापस करें, -- `"calc…"` -- कुछ गणना करो, -- `"create…"` -- कुछ बनाये, -- `"check…"` -- कुछ जांचें और एक बूलियन लौटाएं, आदि। +- `"get…"` -- return a value, +- `"calc…"` -- calculate something, +- `"create…"` -- create something, +- `"check…"` -- check something and return a boolean, etc. -ऐसे नामों के उदाहरण: +Examples of such names: ```js no-beautify -showMessage(..) // एक संदेश दिखाता है -getAge(..) // उम्र लौटाता है (इसे किसी तरह प्राप्त करता है) -calcSum(..) // एक योग की गणना करता है और परिणाम देता है -createForm(..) // एक फॉर्म बनाता है (और आमतौर पर इसे वापस करता है) -checkPermission(..) // अनुमति की जाँच करता है, सही/गलत लौटाता है +showMessage(..) // shows a message +getAge(..) // returns the age (gets it somehow) +calcSum(..) // calculates a sum and returns the result +createForm(..) // creates a form (and usually returns it) +checkPermission(..) // checks a permission, returns true/false ``` -उपसर्गों के साथ, function नाम पर एक नज़र यह समझ देती है कि यह किस प्रकार का कार्य करता है और यह किस प्रकार का मूल्य देता है। +With prefixes in place, a glance at a function name gives an understanding what kind of work it does and what kind of value it returns. ```smart header="One function -- one action" -एक function को ठीक वही करना चाहिए जो उसके नाम से सुझाया गया है, और कुछ नहीं। +A function should do exactly what is suggested by its name, no more. -दो स्वतंत्र क्रियाएं आम तौर पर दो functions की सेवा करती हैं, भले ही उन्हें आम तौर पर एक साथ बुलाया जाता है (उस स्थिति में हम एक तीसरा function बना सकते हैं जो उन दोनों को कॉल करता है)। +Two independent actions usually deserve two functions, even if they are usually called together (in that case we can make a 3rd function that calls those two). -इस नियम को तोड़ने के कुछ उदाहरण: +A few examples of breaking this rule: -- `getAge` -- बुरा होगा अगर यह उम्र के साथ एक `alert` दिखाता है (सिर्फ उम्र लेना चाहिए)। -- `createForm` -- खराब होगा यदि यह डॉक्यूमेंट को संशोधित करता है, इसमें एक फॉर्म जोड़ता है (केवल इसे बनाना और वापस करना चाहिए)। -- `checkPermission` -- खराब होगा यदि यह `access granted/denied` संदेश प्रदर्शित करता है (केवल जांच करना चाहिए और परिणाम वापस करना चाहिए)। +- `getAge` -- would be bad if it shows an `alert` with the age (should only get). +- `createForm` -- would be bad if it modifies the document, adding a form to it (should only create it and return). +- `checkPermission` -- would be bad if it displays the `access granted/denied` message (should only perform the check and return the result). -ये उदाहरण उपसर्गों के सामान्य अर्थ ग्रहण करते हैं। आप और आपकी टीम अन्य अर्थों पर सहमत होने के लिए स्वतंत्र हैं, लेकिन आमतौर पर, वे बहुत भिन्न नहीं होते हैं। किसी भी मामले में, आपको इस बात की पक्की समझ होनी चाहिए कि उपसर्ग का क्या अर्थ है, उपसर्ग का function क्या कर सकता है और क्या नहीं। सभी समान-उपसर्ग function को नियमों का पालन करना चाहिए। और टीम को ज्ञान साझा करना चाहिए। +These examples assume common meanings of prefixes. You and your team are free to agree on other meanings, but usually they're not much different. In any case, you should have a firm understanding of what a prefix means, what a prefixed function can and cannot do. All same-prefixed functions should obey the rules. And the team should share the knowledge. ``` ```smart header="Ultrashort function names" -*अक्सर* उपयोग किए जाने वाले functions में कभी-कभी अल्ट्रा-शॉर्ट नाम होते हैं। +Functions that are used *very often* sometimes have ultrashort names. -उदाहरण के लिए, [jQuery](http://jquery.com) फ्रेमवर्क `$` के साथ एक function को परिभाषित करता है। The [Lodash](http://lodash.com/) library का मुख्य function `_` है। +For example, the [jQuery](http://jquery.com) framework defines a function with `$`. The [Lodash](http://lodash.com/) library has its core function named `_`. -ये अपवाद हैं। आम तौर पर functions नाम संक्षिप्त और वर्णनात्मक होने चाहिए। +These are exceptions. Generally functions names should be concise and descriptive. ``` ## Functions == Comments -Functions छोटे होने चाहिए और ठीक एक काम करना चाहिए। अगर वह चीज बड़ी है, तो शायद यह function को कुछ छोटे functions में विभाजित करना बेहतर है। कभी-कभी इस नियम का पालन करना इतना आसान नहीं हो सकता है, लेकिन यह निश्चित रूप से एक अच्छी बात है। +Functions should be short and do exactly one thing. If that thing is big, maybe it's worth it to split the function into a few smaller functions. Sometimes following this rule may not be that easy, but it's definitely a good thing. -एक अलग function न केवल परीक्षण और डीबग करना आसान है - इसका अस्तित्व एक महान comment है! +A separate function is not only easier to test and debug -- its very existence is a great comment! -उदाहरण के लिए, नीचे दिए गए दो functions `showPrimes(n)` की तुलना करें। हर एक `n` तक [अभाज्य संख्याएँ](https://en.wikipedia.org/wiki/Prime_number) आउटपुट करता है। +For instance, compare the two functions `showPrimes(n)` below. Each one outputs [prime numbers](https://en.wikipedia.org/wiki/Prime_number) up to `n`. -पहला संस्करण एक लेबल का उपयोग करता है: +The first variant uses a label: ```js function showPrimes(n) { nextPrime: for (let i = 2; i < n; i++) { + for (let j = 2; j < i; j++) { if (i % j == 0) continue nextPrime; } - alert( i ); // एक अभाज्य संख्या + alert( i ); // a prime } } ``` -दूसरा संस्करण अभाज्यता के परीक्षण के लिए एक अतिरिक्त function `isPrime(n)` का उपयोग करता है: +The second variant uses an additional function `isPrime(n)` to test for primality: ```js function showPrimes(n) { @@ -442,7 +445,7 @@ function showPrimes(n) { for (let i = 2; i < n; i++) { *!*if (!isPrime(i)) continue;*/!* - alert(i); // एक अभाज्य संख्या + alert(i); // a prime } } @@ -454,13 +457,13 @@ function isPrime(n) { } ``` -दूसरा संस्करण समझना आसान है, है ना? कोड पीस के बजाय हम क्रिया का एक नाम देखते हैं (`isPrime`)। कभी-कभी लोग ऐसे कोड को _स्वयं का वर्णन करना_ कहते हैं। +The second variant is easier to understand, isn't it? Instead of the code piece we see a name of the action (`isPrime`). Sometimes people refer to such code as *self-describing*. -इसलिए, function बनाए जा सकते हैं, भले ही हम उनका पुन: उपयोग करने का इरादा न रखते हों। वे कोड की संरचना करते हैं और इसे पठनीय बनाते हैं। +So, functions can be created even if we don't intend to reuse them. They structure the code and make it readable. -## सारांश +## Summary -एक function घोषणा इस तरह दिखती है: +A function declaration looks like this: ```js function name(parameters, delimited, by, comma) { @@ -468,18 +471,18 @@ function name(parameters, delimited, by, comma) { } ``` -- किसी function को दिए गए मान parameters के रूप में उसके स्थानीय variables में कॉपी किए जाते हैं। -- एक function बाहरी variables का इस्तेमाल कर सकता है। लेकिन यह केवल अंदर से बाहर काम करता है। function के बाहर का कोड इसके स्थानीय variables नहीं देखता है। -- एक function एक मान वापस कर सकता है। यदि ऐसा नहीं होता है, तो इसका परिणाम `undefined` होता है। +- Values passed to a function as parameters are copied to its local variables. +- A function may access outer variables. But it works only from inside out. The code outside of the function doesn't see its local variables. +- A function can return a value. If it doesn't, then its result is `undefined`. -कोड को साफ और समझने में आसान बनाने के लिए, function में मुख्य रूप से स्थानीय variables और parameter का उपयोग करने की अनुशंसा की जाती है, बाहरी variables नहीं। +To make the code clean and easy to understand, it's recommended to use mainly local variables and parameters in the function, not outer variables. -ऐसे function को समझना हमेशा आसान होता है जो parameter प्राप्त करता है, उनके साथ काम करता है, और किसी ऐसे function की तुलना में परिणाम देता है जिसमें कोई parameter नहीं होता है, लेकिन बाहरी variables को साइड-इफेक्ट के रूप में संशोधित करता है। +It is always easier to understand a function which gets parameters, works with them and returns a result than a function which gets no parameters, but modifies outer variables as a side-effect. -Function नामकरण: +Function naming: -- एक नाम स्पष्ट रूप से वर्णन करना चाहिए कि function क्या करता है। जब हम कोड में एक function कॉल देखते हैं, तो एक अच्छा नाम हमें तुरंत समझा देता है कि यह क्या करता है और क्या वापस लौटता है। -- एक function एक क्रिया है, इसलिए function नाम आमतौर पर मौखिक होते हैं। -- कई प्रसिद्ध function प्रीफ़िक्स मौजूद हैं जैसे `create…`, `show…`, `get…`, `check…` और इसी तरह। function क्या करता है यह संकेत देने के लिए उनका उपयोग करें। +- A name should clearly describe what the function does. When we see a function call in the code, a good name instantly gives us an understanding what it does and returns. +- A function is an action, so function names are usually verbal. +- There exist many well-known function prefixes like `create…`, `show…`, `get…`, `check…` and so on. Use them to hint what a function does. -Function स्क्रिप्ट के मुख्य निर्माण खंड हैं। अब हमने मूल बातें शामिल कर ली हैं, इसलिए हम वास्तव में उन्हें बनाना और उनका उपयोग करना शुरू कर सकते हैं। लेकिन यह सिर्फ रास्ते की शुरुआत है। हम कई बार उनके पास वापस जायेंगे, उन्नत सुविधाओं में और अधिक गहराई से इनको जानेंगे। +Functions are the main building blocks of scripts. Now we've covered the basics, so we actually can start creating and using them. But that's only the beginning of the path. We are going to return to them many times, going more deeply into their advanced features. From b1513885ab559ef13235384371f976f6568bcdac Mon Sep 17 00:00:00 2001 From: Rasool Khan <35368463+rskhan167@users.noreply.github.com> Date: Fri, 15 Oct 2021 17:44:12 +0530 Subject: [PATCH 43/43] Update task.md --- 1-js/02-first-steps/15-function-basics/3-min/task.md | 1 + 1 file changed, 1 insertion(+) diff --git a/1-js/02-first-steps/15-function-basics/3-min/task.md b/1-js/02-first-steps/15-function-basics/3-min/task.md index b8bee1341..50edd0d36 100644 --- a/1-js/02-first-steps/15-function-basics/3-min/task.md +++ b/1-js/02-first-steps/15-function-basics/3-min/task.md @@ -13,3 +13,4 @@ min(2, 5) == 2 min(3, -1) == -1 min(1, 1) == 1 ``` +