diff --git a/1-js/01-getting-started/1-intro/article.md b/1-js/01-getting-started/1-intro/article.md index 2f4f518f3..f26f3fb24 100644 --- a/1-js/01-getting-started/1-intro/article.md +++ b/1-js/01-getting-started/1-intro/article.md @@ -1,122 +1,122 @@ -# An Introduction to JavaScript +# Ներածություն -Let's see what's so special about JavaScript, what we can achieve with it, and what other technologies play well with it. +Եկեք տեսնենք, թե ինչ հատկություններ ունի JavaScript-ը, ինչի կարող ենք հասնել նրանով, և ուրիշ ինչ տեխնոլոգիաներ են դրա հետ լավ աշխատում։ -## What is JavaScript? +## Ի՞նչ է JavaScript-ը (ՋավաՍքրիփթ) -*JavaScript* was initially created to "make web pages alive". +*JavaScript-ը* սկզբից ստեղծվել է, որպեսզի *«կյանք տա կայքերին»*։ -The programs in this language are called *scripts*. They can be written right in a web page's HTML and run automatically as the page loads. +Այս լեզվում ծրագրերը կոչվում են *script-ներ* (սքրիփթ). Նրանք կարող են գրվել ուղղակիորեն կայքի HTML-ի (Էյչ-Թի-Էմ-Էլ) մեջ և աշխատել ավտոմատ կերպով, երբ էջը բեռնվի։ -Scripts are provided and executed as plain text. They don't need special preparation or compilation to run. +Script-ների ներկայացվում և աշխատում են ինչպես հասարակ տեքստ։ Նրանք կարիք չունեն հատուկ նախապատրաստության աշխատելուց առաջ։ -In this aspect, JavaScript is very different from another language called [Java](https://en.wikipedia.org/wiki/Java_(programming_language)). +Այս առումով JavaScript-ը շատ է տարբերվում մեկ այլ լեզվից, որը կոչվում է [Java](https://en.wikipedia.org/wiki/Java_(programming_language)): -```smart header="Why is it called JavaScript?" -When JavaScript was created, it initially had another name: "LiveScript". But Java was very popular at that time, so it was decided that positioning a new language as a "younger brother" of Java would help. +```smart header="Ինչու՞ JavaScript" +Երբ JavaScript ստեղծվել էր, այն սկզբում ուրիշ անուն ուներ՝ «LiveScript» (ԼայվՍքրիփթ)։ Սակայն Java-ն շատ տարածված էր այդ ժամանակ, և որոշվեց, որ լեզվի տարածմանը կօգնի ներկայացնել նոր լեզուն ինչպես Java-ի «կրտսեր եղբայր»։ -But as it evolved, JavaScript became a fully independent language with its own specification called [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript), and now it has no relation to Java at all. +Բայց երբ այն զարգացավ, JavaScript-ը դարձավ լիովին անկախ լեզու՝ իր հատկանշական մասերով, որոնք անվանվեցին [ECMAScript](http://en.wikipedia.org/wiki/ECMAScript) (ԷՔՄԱՍքրիփթ), և հիմա այն ընդհանրապես ոչ մի կապ չունի Java-ի հետ։ ``` -Today, JavaScript can execute not only in the browser, but also on the server, or actually on any device that has a special program called [the JavaScript engine](https://en.wikipedia.org/wiki/JavaScript_engine). +Այսօր, JavaScript-ը կարող է աշխատել ոչ միայն browser-ներում (բրաուզեր), այլ նաև server-ներում (սերվեր), կամ ցանկացած սարքերում, որոնք ունեն մի հատուկ ծրագիր, որը կոչվում է [JavaScript engine](https://en.wikipedia.org/wiki/JavaScript_engine) (ՋավաՍքրիթփ էնջըն). -The browser has an embedded engine sometimes called a "JavaScript virtual machine". +Browser-ն ունի իր մեջ ներառված engine, որը նաև անվանում են «JavaScript virtual machine» (ՋավաՍքրիփթ վըրչուըլ մըշին)։ -Different engines have different "codenames". For example: +Տարբեր engin-ներ ունեն տարբեր «կեղծանուններ»՝ -- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome, Opera and Edge. -- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox. -- ...There are other codenames like "Chakra" for IE, "JavaScriptCore", "Nitro" and "SquirrelFish" for Safari, etc. +- [V8](https://hy.wikipedia.org/wiki/V8_(JavaScript_%D5%B7%D5%A1%D6%80%D5%AA%D5%AB%D5%B9)) -- Chrome-ում, Opera-ում և Edge-ում։ +- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- Firefox-ում։ +- ...Կան այլ կեղծանուններ, ինչպես «Chakra» IE-ի համար, «JavaScriptCore», «Nitro» և «SquirrelFish»՝ Safari-ի համար, և այլն։ -The terms above are good to remember because they are used in developer articles on the internet. We'll use them too. For instance, if "a feature X is supported by V8", then it probably works in Chrome, Opera and Edge. +Նշված տերմինները պետք է հիշել, քանի որ նրանք շատ են օգտագործվում համացանցի հոդվածներում։ Մենք նույնպես կօգտագործենք։ Օրինակ, եթե նշված է, որ «Ա հատկությունը օգտագործվում է V8-ում», ապա այն հավանաբար կաշխատի Chrome-ում, Opera-ում և Edge-ում։ -```smart header="How do engines work?" +```smart header="Ինչպե՞ս են աշխատում engine-ները" -Engines are complicated. But the basics are easy. +Engine-ները բարդ են, բայց հիմունքները այդքան էլ դժվար չէ հասկանալ։ -1. The engine (embedded if it's a browser) reads ("parses") the script. -2. Then it converts ("compiles") the script to machine code. -3. And then the machine code runs, pretty fast. +1. Engine-ը (ներառվածը, եթե browser-ի մասին է խոսքը) կարդում է (parse) script-ը։ +2. Ապա այն փոխում է (compile) script-ը մեքենայական կոդի։ +3. Վերջապես մեքենան աշխատեցնում է կոդը, բավականին արագ։ -The engine applies optimizations at each step of the process. It even watches the compiled script as it runs, analyzes the data that flows through it, and further optimizes the machine code based on that knowledge. +Engine-ը բարեփոխումներ (optimization) է անում ամեն քայլին։ Այն նույնիսկ հետևում է պատրաստ script-ի աշխատանքի ընթացքին, վերլուծում տվյալների հոսքը և կրկին բարեփոխումներ կատարում այդ գիտելիքների օգնությամբ։ Երբ դա արված է, script-ը շատ արագ է աշխատում։ ``` -## What can in-browser JavaScript do? +## Ի՞նչ է կարող browser-ի միջի JavaScript-ը անել Modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or the CPU, because it was initially created for browsers which do not require it. -JavaScript's capabilities greatly depend on the environment it's running in. For instance, [Node.js](https://wikipedia.org/wiki/Node.js) supports functions that allow JavaScript to read/write arbitrary files, perform network requests, etc. +JavaScript-ի հնարավորությունները մեծ մասով կախված են միջավայրից, որում այն աշխատում է։ Օրինակ՝ [Node.js](https://wikipedia.org/wiki/Node.js)-ը ունի ֆունկցիաներ, որոնք թույլատրում են JavaScript-ին կարդալ կամ գրել որևէ ֆայլի մեջ, կատարել ցանցային հարցումներ և այլն։ -In-browser JavaScript can do everything related to webpage manipulation, interaction with the user, and the webserver. +Browser-ի միջի JavaScript-ը կարող է անել ամեն ինչ կապված կայքերի կառավարման հետ և օգտագործողի և server-ի կապի հետ։ver. -For instance, in-browser JavaScript is able to: +Օրինակ՝ browser-ի միջի JavaScript-ը կարող է՝to: -- Add new HTML to the page, change the existing content, modify styles. -- React to user actions, run on mouse clicks, pointer movements, key presses. -- Send requests over the network to remote servers, download and upload files (so-called [AJAX](https://en.wikipedia.org/wiki/Ajax_(programming)) and [COMET](https://en.wikipedia.org/wiki/Comet_(programming)) technologies). -- Get and set cookies, ask questions to the visitor, show messages. -- Remember the data on the client-side ("local storage"). +- Ավելացնել նոր HTML էջ, փոխել ներկա պարունակությունը, փոխել ոճը։ +- Պատասխանել օգտագործողի գործողություններին, աշխատել մկնիկի սեղման, շարժման ժամանակ։ +- Ուղարկել հարցումներ համացանցով server-ների, ներբեռնել և վերբեռնել ֆայլեր (այսպես կոչված [AJAX](https://en.wikipedia.org/wiki/Ajax_(programming)) և [COMET](https://en.wikipedia.org/wiki/Comet_(programming)) տեխնոլոգիաներ)։ +- Ստանալ և փոխել cookie-ներ, հարցեր տալ հաճախորդին, ցույց տալ նամակներ։ +- Հիշել օգտատերի տվյալները («local storage»). -## What CAN'T in-browser JavaScript do? +## Ի՞նչ չի կարող JavaScript-ը անել -JavaScript's abilities in the browser are limited to protect the user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data. +JavaScript-ի հնարավորությունները browser-ում սահմանափակ են ապահովության նկատառումներով։ Նպատակն է կանխել չարամիտ կայքերի հասանելիությունը օգտագործողի անձնական տվյալներին։ -Examples of such restrictions include: +Այսպիսի սահմանափակումների օրինակներ են՝ -- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS functions. +- JavaScript-ը էջում չի կարող կարդալ գամ գրել որևը կոշտ սկավառակը ֆայլի մեջ, պատճենել դրանք կամ աշխատեցնել ծրագրեր։ Այն չունի ուղիղ հասանելիություն օպերացիոն համակարգի ֆունկցիաներին։ - Modern browsers allow it to work with files, but the access is limited and only provided if the user does certain actions, like "dropping" a file into a browser window or selecting it via an `` tag. + Ժամանակակից browser-ները թույլ են տալիս աշխատել ֆայլերի հետ, բայց հասանելիությունը տրամադրվում է միայն որոշակի դեպքերում, օրինակ՝ երբ օգտագործողը «նետում» է ֆայլերը պատուհանի մեջ կամ ընտրում `` tag-ի միջոցով։ - There are ways to interact with the camera/microphone and other devices, but they require a user's explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the [NSA](https://en.wikipedia.org/wiki/National_Security_Agency). -- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other page if they come from different sites (from a different domain, protocol or port). + Գոյություն ունեն մեթոդներ տեսախցիկին, կամ խոսափողին և այլ սարքերնի հասանելիություն տրամադրելու, բայց դրանք պահանջում են օգտագործողի կողմից կատարված կամավոր գործողություն, որպեսզի էջը գաղտնիաբար չօգտագործի տեսախցիկը և տվյալներ ուղարկի [NSA](https://en.wikipedia.org/wiki/National_Security_Agency)-ին։ +- Տարբեր պատուհանները հիմնականում չգիտեն իրար մասին։ Որոշ դեպքերում, սակայն, գիտեն, օրինակ՝ երբ մի էջը օգտագործում է JavaScript, որ բացի մյուսը։ Սակայն նույնիսկ այս դեպքում, մի էջի JavaScript-ը չի կարող հասանելիություն ունենալ մյուս էջին, եթե նրանք տարբեր կայքից են (տարբեր դոմեյնից, protocol-ից կամ port-ից)։ - This is called the "Same Origin Policy". To work around that, *both pages* must agree for data exchange and must contain special JavaScript code that handles it. We'll cover that in the tutorial. + Սա կոչվում է «Same Origin Policy»։ Երկու էջերն էլ պետք է պայմանավորվեն տվյալների փոխանակման համար և պարունակեն հատուկ JavaScript կոդ, որը կառավարում է դա։ Մենք կխոսենք դրա մասին դասընթացի մեջ։ - This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com`, for example, and steal information from there. -- JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation. + Այս սահմանափակումը, նույնպես, օգտագործողի ապահովության համար է։ `http://anysite.com`-ից էջը, որը օգտագործողը բացել է, չպետք է հասանելիություն ունենա ուրիշ պատուհանին, օրինակ `http://gmail.com`-ին, ու գողանա տվյալներ։ +- JavaScript-ը կարող է հեշտորեն կապվել ցանցով server-ի հետ, որտեղից որ կայքը գալիս է։ Բայց նրա հնարավորությունը, տվյալներ ստանալ այլ աղբյուրներից, սահմանափակ է։ Չնայած, որ հնարավոր է, սակայն այն պահանջում է հատուկ համաձայնություն (արտահայտված HTTP header-ներով) server-ից։ Կրկին, սա արված է օգտագործողի ապահովության համար։ ![](limitations.svg) -Such limitations do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugins/extensions which may ask for extended permissions. +Այսպիսի սահմանափակումներ չկան, երբ JavaScript-ը օգտագործվում է browser-ից դուրս, օրինակ՝ server-ներում։ Ժամանակակից browser-ները նույնպես ունեն plug-in-ներ, որոնք կարող են հարցնել հավելյալ թույլտվություններ։ -## What makes JavaScript unique? +## Ի՞նչն է դարձնում JavaScript-ը յուրօրինակ -There are at least *three* great things about JavaScript: +Կան գոնե *երեք* լավ բաներ JavaScript-ի մասին՝ ```compare -+ Full integration with HTML/CSS. -+ Simple things are done simply. -+ Supported by all major browsers and enabled by default. ++ HTML/CSS-ի հետ ներառում։ ++ Հասարակ բաները արվում են հասարակ կերպով։ ++ Բոլոր մեծ browser-ները աշխատում են JavaScript—ի հետ։ ``` -JavaScript is the only browser technology that combines these three things. +JavaScript-ը միակ browser-ային տեխնոլոգիան է, որը ներառում է այս 3 կետերը։ -That's what makes JavaScript unique. That's why it's the most widespread tool for creating browser interfaces. +Ահա, թե ինչն է սարքում դրան այսքան տարբերվող։ Ահա, թե ինչու է ամենատարածված գործիքը browser-ային ինտերֆեյսեր սարքելու համար։ -That said, JavaScript can be used to create servers, mobile applications, etc. +Ինչպես նաև, JavaScript-ը թույլ է տալիս ստեղծել server-ներ, mobile ծրագրեր և այլն։ -## Languages "over" JavaScript +## Լեզուներ՝ JavaScript-ի «վրա» -The syntax of JavaScript does not suit everyone's needs. Different people want different features. +JavaScript-ի գրելաձևը բոլորին չի բավարարում։ Տարբեր մարդիկ ցանկանում են տարբեր հատկություններ։ -That's to be expected, because projects and requirements are different for everyone. +Դա սպասելի է, քանի որ ծրագրերն ու պահանջները տարբեր են բոլորի մոտ։ -So, recently a plethora of new languages appeared, which are *transpiled* (converted) to JavaScript before they run in the browser. +Վերջերս բազում նոր լեզուներ են առաջացել, որոնք *transpile* են լինում (փոխվում) JavaScript-ի մինչև browser-ում աշխատելը։ -Modern tools make the transpilation very fast and transparent, actually allowing developers to code in another language and auto-converting it "under the hood". +Ժամանակակից գործիքները դարձնում են փոփոխվելը շատ արագ և թափանցիկ, թույլատրելով ծրագրավորողներին աշխատել այլ լեզվով, և ավտո-փոխակերպում են այն JavaScript-ի աննկատ կերպով։ -Examples of such languages: +Այսպիսի լեզուների օրինակներ են՝ -- [CoffeeScript](https://coffeescript.org/) is "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it. -- [TypeScript](https://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft. -- [Flow](https://flow.org/) also adds data typing, but in a different way. Developed by Facebook. -- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google. -- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript. -- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) is a modern, concise and safe programming language that can target the browser or Node. +- [CoffeeScript](https://coffeescript.org/)-ը ունի կարճ գրելաձև, թույլ է տալիս ծրագրավորողին գրել ավելի մաքուր և ճշգրիտ կոդ։ Հիմնականում Ruby-ի ծրագրավորողներն են հավանում այն։ +- [TypeScript](https://www.typescriptlang.org/)-ը կենտրոնացած է խիստ տիպերի ներմուծման վրա, հեշտացնելով դժվար համակարգերի ծրագրավորումն ու հետագա ապահովումը։ Այն ստեղծվել է Microsoft-ի կողմից։ +- [Flow](https://flow.org/)-ը նույնպես ավելացնում է տվյալների տիպեր, սակայն այլ կերպ է աշխատում։ Ստեղծված է Facebook-ի կողմից։ +- [Dart](https://www.dartlang.org/)-ը առանձին լեզու է, որը ունի իր սեփական engine-ը և աշխատում է ոչ-browser-ային միջավայրներում, ինչպես mobile ծրագրերում, սակայն կարող է թարգմանվել JavaScript-ի։ Ստեղծվել է Google-ի կողմից։ +- [Brython](https://brython.info/) թարգմանում է Python-ը JavaScript-ի։ +- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) ժամանակակից, հակիրճ և ապահով ծրագրավորման լեզու է, կա հնարավորություն կոդը թարգմանելու նաև browser-ների or Node-ի համար։ -There are more. Of course, even if we use one of these transpiled languages, we should also know JavaScript to really understand what we're doing. +Կան ուրիշներ։ Իհարկե, եթե նույնիսկ օգտագործենք թարգմանված լեզուները, պետք է իմանանք JavaScript, որպեսզի հասկանանք՝ ինչ ենք անում։ -## Summary +## Ամփոփում -- JavaScript was initially created as a browser-only language, but it is now used in many other environments as well. -- Today, JavaScript has a unique position as the most widely-adopted browser language, fully integrated with HTML/CSS. -- There are many languages that get "transpiled" to JavaScript and provide certain features. It is recommended to take a look at them, at least briefly, after mastering JavaScript. +- JavaScript-ը սկզբում ստեղծվել է միայն browser-ների համար, սակայն այն հիմա օգտագործվում է շատ այլ միջավայրներում նույնպես։ +- Այսօր JavaScript-ը ունի իր ուրույն տեղը որպես ամենաընդունված browser-ի լեզու, HTML/CSS-ի հետ լրիվ ներառմամբ։ +- Կան շատ լեզուներ, որոնք «թարգմանվում» են JavaScript-ի և տրամադրում որոշ հատկություններ։ Խորհուրդ է տրվում աչքի անցկացնել դրանք, գոնե մակերեսային, JavaScript-ում խորանալուց հետո։ diff --git a/1-js/01-getting-started/2-manuals-specifications/article.md b/1-js/01-getting-started/2-manuals-specifications/article.md index 3fa243336..5a5e356e8 100644 --- a/1-js/01-getting-started/2-manuals-specifications/article.md +++ b/1-js/01-getting-started/2-manuals-specifications/article.md @@ -1,37 +1,37 @@ -# Manuals and specifications +# Ձեռնարկներ և բնութագրեր -This book is a *tutorial*. It aims to help you gradually learn the language. But once you're familiar with the basics, you'll need other resources. +Այս գիրքը *ուսուցողական ձեռնարկ* է, որի նպատակն է օգնել Ձեզ աստիճանաբար յուրացնել լեզուն: Երբ ծանոթանաք հիմնական հասկացություններին, ուսուցումը շարունակելու համար այլ աղբյուրների կարիք կլինի: -## Specification +## Բնութագիր (Specification) -[The ECMA-262 specification](https://www.ecma-international.org/publications/standards/Ecma-262.htm) contains the most in-depth, detailed and formalized information about JavaScript. It defines the language. +[ECMA-262 ստանդարտը](https://www.ecma-international.org/publications/standards/Ecma-262.htm) պարունակում է ամենախորը, մանրամասն և պատշոնապես ձևակերպված տեղեկատվությունը JavaScript-ի մասին: Այն սահմանում է լեզուն: -But being that formalized, it's difficult to understand at first. So if you need the most trustworthy source of information about the language details, the specification is the right place. But it's not for everyday use. +Բայց լեզվի նման ձևակերպումը դժվար է հասկանալ սկզբում: Եթե Ձեզ պետք է լեզվի մանրամասների մասին տեղեկատվության ամենավստահելի աղբյուրը, ապա այս պաշտոնական փաստաթուղթն է հենց այդ աղբյուրը: Սակայն այն նախատեսված չէ ամենօրյա օգտագործման համար: -A new specification version is released every year. Between these releases, the latest specification draft is at . +Ամեն տարի թողարկվում է հատկորոշման նոր տարբերակ: Այս թողարկումների միջև ամենաթարմ սևագիրը գտնվում է հասցեում: -To read about new bleeding-edge features, including those that are "almost standard" (so-called "stage 3"), see proposals at . +Լեզվի նորագույն հնարավորությունների մասին կարդալու համար (ներառյալ «գրեթե ստանդարտ»՝ այսպես կոչված «stage 3» հնարավորությունները) այցելեք առաջարկությունների կայքը՝ հասցեով: -Also, if you're developing for the browser, then there are other specifications covered in the [second part](info:browser-environment) of the tutorial. +Ինչպես նաև, եթե Դուք լուծում եք մշակում վեբ զննիչների համար, ապա ձեռնարկի [երկրորդ մասում](info:browser-environment) ունենք տեղեկատվություն այլ բնութագրերի մասին: -## Manuals +## Ձեռնարկներ -- **MDN (Mozilla) JavaScript Reference** is the main manual with examples and other information. It's great to get in-depth information about individual language functions, methods etc. +- **MDN (Mozilla) JavaScript Reference**-ը հիմնական ձեռնարկ է՝ հագեցած օրինակներով և այլ տեղեկություններով: Այն օգտակար է լեզվի առանձին հնարավորությունների, մեթոդների և այլնի մասին խորացած տեղեկություններ ստանալու համար. - You can find it at . + Այն կարելի է գտնել հասցեով: -Although, it's often best to use an internet search instead. Just use "MDN [term]" in the query, e.g. to search for the `parseInt` function. +Հաճախ ավելի լավ է կատարել որոնում համացանցում: Ուղղակի օգտագործեք "MDN [տերմին]"-ը որոնման մեջ, օրինակ՝ , `parseInt` ֆունկցիան որոնելու համար. -## Compatibility tables +## Համատեղելիության աղյուսակներ -JavaScript is a developing language, new features get added regularly. +JavaScript-ը զարգացող լեզու է, և պարբերաբար նոր հնարավորություններ են ավելացվում: -To see their support among browser-based and other engines, see: +Օգտվեք հետևյալ կայքերից՝ տարբեր վեբ զննիչներում և շարժիչներում դրանց հասանելիությունը ստուգելու համար. -- - per-feature tables of support, e.g. to see which engines support modern cryptography functions: . -- - a table with language features and engines that support those or don't support. +- - աջակցության աղյուսակներ՝ յուրաքանչյուր հատկանիշի համար, օրինակ՝ ցույց է տալիս այն շարժիչները, որոնցում սպասարկվում են գաղտնագրման ժամանակակից ֆուկցիաները: : +- - աղյուսակ է, կազմված լեզվի հնարավորություններից և շարժիչներից, որոնցում այդ հնարավորությունները սպասարկվում են կամ չեն սպասարկվում: -All these resources are useful in real-life development, as they contain valuable information about language details, their support, etc. +Բոլոր այս կայքերն օգտակար են առօրյա աշխատանքում, քանի որ պարունակում են արժեքավոր տեղեկություններ լեզվի հատկանիշների, դրանց սպասարկման մասին և այլն․․․ -Please remember them (or this page) for the cases when you need in-depth information about a particular feature. +Խնդրում ենք մտապահել այդ կայքերը (կամ այս էջը) այն դեպքերի համար, երբ անհրաժեշտ կլինի մանրամասն տեղեկություններ ստանալ որևէ հնարավորության մասին: diff --git a/1-js/01-getting-started/3-code-editors/article.md b/1-js/01-getting-started/3-code-editors/article.md index ca6194741..96ef12669 100644 --- a/1-js/01-getting-started/3-code-editors/article.md +++ b/1-js/01-getting-started/3-code-editors/article.md @@ -1,49 +1,49 @@ -# Code editors +# Խմբագրիչներ -A code editor is the place where programmers spend most of their time. +Ծրագրավորողները ժամանակի մեծ մասն անցկացում են խմբագրիչներում: -There are two main types of code editors: IDEs and lightweight editors. Many people use one tool of each type. +Կան երկու հիմնական տիպի խմբագրիչներ. IDE-ներ (ամբողջացված մշակման միջավայրեր) և թեթև խմբագրիչներ: Շատերն օգտագործում են դրանցից որևէ մեկը: ## IDE -The term [IDE](https://en.wikipedia.org/wiki/Integrated_development_environment) (Integrated Development Environment) refers to a powerful editor with many features that usually operates on a "whole project." As the name suggests, it's not just an editor, but a full-scale "development environment." +[IDE](https://en.wikipedia.org/wiki/Integrated_development_environment)-ն (ամբողջացված մշակման միջավայր) հզոր խմբագրիչ է բազմաթիվ հնարավորություններով, որում կարելի է մշակել և կառավարել ամբողջական նախագծեր: Ինչպես անունն է հուշում՝ այն ուղղակի խմբագրիչ չէ, այլ մշակման ամփոփ միջավայր: -An IDE loads the project (which can be many files), allows navigation between files, provides autocompletion based on the whole project (not just the open file), and integrates with a version management system (like [git](https://git-scm.com/)), a testing environment, and other "project-level" stuff. +IDE-ն բեռնում է նախագիծը (որը կարող է պարունակել բազմաթիվ ֆայլեր), թույլ է տալիս նավարկել ֆայլերի միջև, տրամադրում է ինքնալրացում (autocompletion), ինտեգրվում է տարբերակների կառավարման համակարգերի (VCS) հետ (օրինակ՝ [git](https://git-scm.com/)), ունի փորձարկման միջավայր և այլն: -If you haven't selected an IDE yet, consider the following options: +IDE-ների օրնակներ են. -- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free). -- [WebStorm](https://www.jetbrains.com/webstorm/) (cross-platform, paid). +- [Visual Studio Code](https://code.visualstudio.com/) (հասանելի է տարբեր հարթակների համար, անվճար է): +- [WebStorm](https://www.jetbrains.com/webstorm/) (հասանելի է տարբեր հարթակների համար, վճարովի է): -For Windows, there's also "Visual Studio", not to be confused with "Visual Studio Code". "Visual Studio" is a paid and mighty Windows-only editor, well-suited for the .NET platform. It's also good at JavaScript. There's also a free version [Visual Studio Community](https://www.visualstudio.com/vs/community/). +Windows-ի համար կա նաև «Visual Studio»-ն, որը տարբերվում է «Visual Studio Code»-ից. «Visual Studio»-ն վճարովի և բազմաֆունկցիոնալ խմբագրիչ է, ստեղծված միայն Windows-ի համար և հարմարեցված .NET հարթակի համար: Ունի նաև [Visual Studio Community](https://www.visualstudio.com/vs/community/) անվճար տարբերակը: -Many IDEs are paid, but have a trial period. Their cost is usually negligible compared to a qualified developer's salary, so just choose the best one for you. +Շատ IDE-ներ վճարովի են, բայց ունեն փորձարկման շրջան: Նրանց գինը սովորաբար աննշան է փորձառու ծրագրավորողի աշխատավարձի հետ համեմատած, այնպես որ ուղղակի ընտրեք այն, որը Ձեր կարիքներին առավել լավ է համապատասխանում: -## Lightweight editors +## Թեթև խմբագրիչներ -"Lightweight editors" are not as powerful as IDEs, but they're fast, elegant and simple. +«Թեթև խմբագրիչներ»-ը IDE-ների նման հզոր չեն, բայց արագագործ են և պարզ: -They are mainly used to open and edit a file instantly. +Հիմնականում օգտագործվում են ֆայլերը արագ խմբագրելու համար: -The main difference between a "lightweight editor" and an "IDE" is that an IDE works on a project-level, so it loads much more data on start, analyzes the project structure if needed and so on. A lightweight editor is much faster if we need only one file. +IDE-ների և «թեթև խմբագրիչներ»-ի հիմնական տարբերությունն այն է, որ IDE-ն աշխատում է նախագծի մակարդակով, բեռնում է շատ ավելի տվայլներ, անհրաժեշտության դեպքում վերլուծում է նախագծի կառուցվածը և այլն: Թեթև խմբագրիչը շատ ավելի արագ է աշխատում, եթե միայն մեկ ֆայլի հետ գործ ունենք: -In practice, lightweight editors may have a lot of plugins including directory-level syntax analyzers and autocompleters, so there's no strict border between a lightweight editor and an IDE. +Գործնականում թեթև խմբագրիչները կարող են ունենալ բազմաթիվ հավելումներ (plugins), որոնք կարող են խմբագրիչի հնարավորություններ մեծացնել, այնպես որ թեթև խմբագրիչների և IDE-ների մեջ խիստ տարանջատում չկա: -There are many options, for instance: +Հետևյալ խնբագրիչներն արժանի են Ձեր ուշադրությանը. -- [Sublime Text](https://www.sublimetext.com/) (cross-platform, shareware). -- [Notepad++](https://notepad-plus-plus.org/) (Windows, free). -- [Vim](https://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them. +- [Sublime Text](http://www.sublimetext.com) (հասանելի է տարբեր հարթակների համար, վճարովի է). +- [Notepad++](https://notepad-plus-plus.org/) (Windows, անվճար է). +- [Vim](http://www.vim.org/), [Emacs](https://www.gnu.org/software/emacs/). -## Let's not argue +## Այլ խմբագրիչներ -The editors in the lists above are those that either I or my friends whom I consider good developers have been using for a long time and are happy with. +Վերոնշյալ խմբագրիչները իմ, իմ ընկերների, որվքեր իմ համար լավ ծրագրավորողներ են օգտագործվում են երկար ժանանակ, և մենք գոհ ենք այդ խմբագրիչներով: -There are other great editors in our big world. Please choose the one you like the most. +Ընդհանրապես ասած գոյություն ունեն նաև այլ խմբագրիչներ: Դուք ազատ են ընտրել այն խմբագրիչը, որ ձեզ դուր է գալիս։ -The choice of an editor, like any other tool, is individual and depends on your projects, habits, and personal preferences. +Խմբագրիչի (ինչպես մնացած գործիքների) ընտրությունը Ձեր անձնական գործն է և կարող է կախված լինել նախագծից, սովորություններից, կամ անձնական նախընտրություններից: -The author's personal opinion: +Հեղինակի անձնական կարծիքը հետևյալն է. -- I'd use [Visual Studio Code](https://code.visualstudio.com/) if I develop mostly frontend. -- Otherwise, if it's mostly another language/platform and partially frontend, then consider other editors, such as XCode (Mac), Visual Studio (Windows) or Jetbrains family (Webstorm, PHPStorm, RubyMine etc, depending on the language). +- Frontend նախագծերի համար ես կօգտագործեի [Visual Studio Code](https://code.visualstudio.com/)։ +- Հակառակ դեպքում, այլ պլատֆորմների/լեզուների համար կդիտարկիե այլ խմբագրչներ, օրինակ XCode (Mac), Visual Studio (Windows) կամ Jetbrains ընտանիքի խմբագրիչ (Webstorm, PHPStorm, RubyMine, և այլն, կախված լեզվից)։ diff --git a/1-js/01-getting-started/4-devtools/article.md b/1-js/01-getting-started/4-devtools/article.md index 50926d4f7..0b214f49b 100644 --- a/1-js/01-getting-started/4-devtools/article.md +++ b/1-js/01-getting-started/4-devtools/article.md @@ -1,63 +1,63 @@ -# Developer console +# Ծրագրավորման բարձակ (Developer console) -Code is prone to errors. You will quite likely make errors... Oh, what am I talking about? You are *absolutely* going to make errors, at least if you're a human, not a [robot](https://en.wikipedia.org/wiki/Bender_(Futurama)). +Կոդը կարող է պարունակել սխալներ: Դուք ամենայն հավանականությամբ թույլ կտաք սխալներ ... Օ, ինչի՞ մասին եմ խոսում: Դուք *անպայման* սխալներ եք գործելու, եթե դուք իհարկե մարդ եք, ոչ թե [ռոբոտ](https://en.wikipedia.org/wiki/Bender_(Futurama))։ -But in the browser, users don't see errors by default. So, if something goes wrong in the script, we won't see what's broken and can't fix it. +Բայց զննիչում օգտվողները հիմնականում չեն տեսնում սխալներ: Այսպիսով, եթե սցենարում ինչ-որ բան այն չէ, մենք չենք տեսնի, թե որն է սխալը և չենք կարող շտկել այն: -To see errors and get a lot of other useful information about scripts, "developer tools" have been embedded in browsers. +Սխալները տեսնելու և սցենարների վերաբերյալ շատ այլ օգտակար տեղեկություններ ստանալու համար «ծրագրավորման գործիքները» տեղադրվել են վեբ զննիչներում: -Most developers lean towards Chrome or Firefox for development because those browsers have the best developer tools. Other browsers also provide developer tools, sometimes with special features, but are usually playing "catch-up" to Chrome or Firefox. So most developers have a "favorite" browser and switch to others if a problem is browser-specific. +Ծրագրավորողներից շատերը ծրագրավորման համար օգտագործում են Chrome կամ Firefox, քանի որ այդ զննիչներն ունեն ծրագրավորման լավագույն գործիքները: Մյուս զննիչներն էլ տրամադրում են ծրագրավորման գործիքներ, որոնք երբեմն ունեն հատուկ առանձնահատկություններ, բայց սովորաբար դրանք նման են Chrome-ի կամ Firefox-ի ծրագրավորման գործիքներին: Այսպիսով, ծրագրավորողների մեծամասնությունը ունի «սիրված» զննիչ և անցնում է մյուս զննիչներին, եթե խնդիրը հատուկ է տվյալ զննիչին: -Developer tools are potent; they have many features. To start, we'll learn how to open them, look at errors, and run JavaScript commands. +Ծրագրավորման գործիքները ուժեղ են, դրանք շատ առանձնահատկություններ ունեն: Սկսելու համար մենք կսովորենք, թե ինչպես բացել դրանք, դիտել սխալները և գործարկել JavaScript հրամաններ: ## Google Chrome -Open the page [bug.html](bug.html). +Բացեք [bug.html](bug.html) էջը։ -There's an error in the JavaScript code on it. It's hidden from a regular visitor's eyes, so let's open developer tools to see it. +Այնտեղ JavaScript կոդի մեջ սխալ կա: Այն թաքնված է սովորական այցելուի աչքից, ուստի եկեք բացենք ծրագրավորման գործիքները՝ այն տեսնելու համար: -Press `key:F12` or, if you're on Mac, then `key:Cmd+Opt+J`. +Սեղմեք `key:F12` կամ, եթե ունեք Mac, սեղմեք `key:Cmd+Opt+J`։ -The developer tools will open on the Console tab by default. +Ծրագրավորման գործիքները ինքնուրույն կբացվեն բարձակի ներդիրում: -It looks somewhat like this: +Դա ունի այսպիսի տեսք։ ![chrome](chrome.png) -The exact look of developer tools depends on your version of Chrome. It changes from time to time but should be similar. +Ծրագրավորման գործիքների տեսքը կախված է Chrome-ի տարբերակից: Այն ժամանակ առ ժամանակ փոխվում է, բայց պետք է հիմնականում նման լինի: -- Here we can see the red-colored error message. In this case, the script contains an unknown "lalala" command. -- On the right, there is a clickable link to the source `bug.html:12` with the line number where the error has occurred. +- Այստեղ մենք կարող ենք տեսնել կարմիրով գունավորված սխալի հաղորդագրությունը: Այս դեպքում սցենարը պարունակում է անհայտ «lalala» հրաման: +- Աջ կողմում կա աղբյուրի վրա սեղմվող հղում `bug.html:12` տողի համարով, որտեղ սխալը տեղի է ունեցել: -Below the error message, there is a blue `>` symbol. It marks a "command line" where we can type JavaScript commands. Press `key:Enter` to run them. +Սխալի հաղորդագրության տակ կա կապույտ գույնի `>` նշան։ Այն նշում է այն տողը, որտեղ մենք կարող ենք մուտքագրել JavaScript հրամաններ: Սեղմեք `key:Enter` դրանք գործարկելու համար: -Now we can see errors, and that's enough for a start. We'll come back to developer tools later and cover debugging more in-depth in the chapter . +Այժմ մենք կարող ենք տեսնել սխալները, որը բավական է սկզբի համար: Ավելի ուշ մենք կանդրադառնանք ծրագրավորման գործիքներին և ավելի խորը կծանոթանանք սխալների ողղմանը հետևյալ գլխում . -```smart header="Multi-line input" -Usually, when we put a line of code into the console, and then press `key:Enter`, it executes. +```smart header="Բազմատող մուտք" +Սովորաբար, երբ մենք կոդ ենք գրում բարձակի (console) մեջ և սեղմում ենք `key:Enter`, այն կատարվում է: -To insert multiple lines, press `key:Shift+Enter`. This way one can enter long fragments of JavaScript code. +Բազմաթիվ տողեր ներմուծելու համար սեղմեք `key:Shift+Enter`։ Այս կերպ կարելի է մուտքագրել JavaScript կոդի երկար ֆրագմենտներ: ``` -## Firefox, Edge, and others +## Firefox, Edge, և ուրիշները -Most other browsers use `key:F12` to open developer tools. +Շատ այլ զննիչներ օգտագործում են `key:F12` ծրագրավորման գործիքները բացելու համար: -The look & feel of them is quite similar. Once you know how to use one of these tools (you can start with Chrome), you can easily switch to another. +Նրանց տեսքը և աշխատանքը բավականին նման է: Երբ իմանաք, թե ինչպես օգտագործել այս գործիքներից մեկը (կարող եք սկսել Chrome-ից), կարող եք հեշտությամբ անցնել մյուսին: ## Safari -Safari (Mac browser, not supported by Windows/Linux) is a little bit special here. We need to enable the "Develop menu" first. +Safari (Mac զննիչ, հասանելի չէ Windows և Linux ՕՀ-երում) այն մի փոքր առանձնահատուկ է: Մենք նախ պետք է միացնենք «ծրագրավորման գործիքները»: -Open Preferences and go to the "Advanced" pane. There's a checkbox at the bottom: +Բացեք Preferences էջը և գնացեք "Advanced" պատուհան։ Ներքևում checkbox կա ծրագրավորման գործիքների համար։ ![safari](safari.png) -Now `key:Cmd+Opt+C` can toggle the console. Also, note that the new top menu item named "Develop" has appeared. It has many commands and options. +Հիմա `key:Cmd+Opt+C` կարող է բացել բարձակը (console): Նաև նշենք, որ հայտնվել է «ծրագրավորման գործիքներ» անվանմամբ ընտրացանկի նոր վերին կետը: Այն ունի շատ հրամաններ և տարբերակներ: -## Summary +## Ամփոփում -- Developer tools allow us to see errors, run commands, examine variables, and much more. -- They can be opened with `key:F12` for most browsers on Windows. Chrome for Mac needs `key:Cmd+Opt+J`, Safari: `key:Cmd+Opt+C` (need to enable first). +- Ծրագրավորման գործիքները մեզ թույլ են տալիս տեսնել սխալներ, գործարկել հրամաններ, ուսումնասիրել փոփոխականները և ավելին: +- Դրանք կարելի է բացել `key:F12` Windows-ի համար նախատեսված շատ զննիչներում՝ օրինակ Chrome-ում։ Mac-ի համար պետք է սեղմել `key:Cmd+Opt+J`, Safari: `key:Cmd+Opt+C` (բայց անհրաժեշտ է նախ ակտիվացնել). -Now we have the environment ready. In the next section, we'll get down to JavaScript. +Այժմ մեր միջավայրը պատրաստ է: Հաջորդ բաժնում մենք կանդրադառնանք JavaScript- ին: diff --git a/1-js/01-getting-started/index.md b/1-js/01-getting-started/index.md index b327c7860..e36a66a4c 100644 --- a/1-js/01-getting-started/index.md +++ b/1-js/01-getting-started/index.md @@ -1,3 +1,3 @@ -# An introduction +# Ներածություն -About the JavaScript language and the environment to develop with it. +JavaScript լեզվի և այն միջավայրի մասին, որով ծրագրավորելու ենք: diff --git a/1-js/02-first-steps/01-hello-world/1-hello-alert/task.md b/1-js/02-first-steps/01-hello-world/1-hello-alert/task.md index afed6a91d..b3650ef64 100644 --- a/1-js/02-first-steps/01-hello-world/1-hello-alert/task.md +++ b/1-js/02-first-steps/01-hello-world/1-hello-alert/task.md @@ -2,11 +2,11 @@ importance: 5 --- -# Show an alert +# Ցուցադրել հաղորդագրություն -Create a page that shows a message "I'm JavaScript!". +Ստեղծեք էջ, որը ցույց է տալիս «I'm JavaScript!» հաղորդագրությունը։ -Do it in a sandbox, or on your hard drive, doesn't matter, just ensure that it works. +Կարող եք անել այստեղ, կամ ձեր համակարգչում, տարբերություն չկա։ Միայն համոզվեք, որ լուծումն աշխատում է։ [demo src="solution"] diff --git a/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/solution.md b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/solution.md index f42c41e6d..50e1a0547 100644 --- a/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/solution.md +++ b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/solution.md @@ -1,8 +1,8 @@ -The HTML code: +HTML կոդը՝ [html src="index.html"] -For the file `alert.js` in the same folder: +`alert.js` ֆայլը՝ [js src="alert.js"] diff --git a/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md index 26168d6a7..3aafb3982 100644 --- a/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md +++ b/1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md @@ -2,8 +2,8 @@ importance: 5 --- -# Show an alert with an external script +# Ցուցադրել հաղորդագրություն արտաքին սկրիպտի միջոցով -Take the solution of the previous task . Modify it by extracting the script content into an external file `alert.js`, residing in the same folder. +Վերցրեք նախորդ խնդրի լուծումը ։ Տեղափոխեք script պիտակի պարունակությունը `alert.js` ֆայլի մեջ, որը պետք է գտնվի նույն պանակում։ -Open the page, ensure that the alert works. +Բացեք էջը և համոզվեք, որ լուծումն աշխատում է։ diff --git a/1-js/02-first-steps/01-hello-world/article.md b/1-js/02-first-steps/01-hello-world/article.md index 35f82bf5d..d5ec0e815 100644 --- a/1-js/02-first-steps/01-hello-world/article.md +++ b/1-js/02-first-steps/01-hello-world/article.md @@ -1,17 +1,17 @@ # Hello, world! -This part of the tutorial is about core JavaScript, the language itself. +Ձեռնարկի այս մասը վերաբերում է բուն JavaScript լեզվին։ -But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like `alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui) of the tutorial. +Մեզ հարկավոր է աշխատանքային միջավայր, որտեղ գործարկելու ենք մեր սկրիպտերը։ Քանի որ այս ձեռնարկը առցանց է, ապա զննիչը լավ ընտրություն է։ Զննիչներին հատուկ հրամանները (օրինակ՝ `alert`) կօգտագործենք հնարավորինս քիչ, որպեսզի դրանց վրա շատ ժամանակ չծախսեք, եթե պլանավորում եք այլ միջավայրում աշխատել (օրինակ՝ Node.js)։ Մենք կկենտրոնանանք զննիչներում JavaScript–ի աշխատանքին ձեռնարկի [հաջորդ բաժնում](/ui)։ -So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like `"node my.js"`. +Սկզբում տեսնենք, թե ինչպես էջին կցել որևէ սկրիպտ։ Սերվերային միջավայրերում (օրինակ՝ Node.js) սկրիպտը կարելի է գործարկել հետևյալ կամ նմանատիպ հրամանով՝ `"node my.js"`։ -## The "script" tag +## «script» պիտակը (tag) -JavaScript programs can be inserted almost anywhere into an HTML document using the ` */!* -

...After the script.

+

...սկրիպտից հետո։

@@ -35,24 +35,24 @@ For instance: ``` ```online -You can run the example by clicking the "Play" button in the right-top corner of the box above. +Կարող եք գործարկել օրինակը սեղմելով «Play» կոճակը։ ``` -The ` ``` - This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the ` ``` -Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"`, just like `src="./script.js"`, would mean a file `"script.js"` in the current folder. +Այստեղ, `/path/to/script.js`–ը կայքի արմատից (root) սկրիպտի բացարձակ ուղին է (absolute path)։ Կարելի է տրամադրել նաև հարաբերական ուղի տվյալ էջից։ Օրինակ՝ `src="script.js"`–ը, ինչպես `src="./script.js"`-ը, նշանակում է, որ `"script.js"` ֆայլը գտնվում է տվյալ պանակում (folder)։ -We can give a full URL as well. For instance: +Կարելի է նաև նշել ամբողջական URL։ Օրինակ՝ ```html ``` -To attach several scripts, use multiple tags: +Մի քանի սկրիպտեր կցելու համար կարելի է օգտագործել մի քանի պիտակներ՝ ```html @@ -90,29 +90,29 @@ To attach several scripts, use multiple tags: ``` ```smart -As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files. +Սովորաբար միայն պարզ սկրիպտերն են ներդնում HTML–ում։ Առավել բարդերը տեղակայվում են առանձին ֆայլերում։ -The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache). +Առանձին ֆայլի առավելությունն այն է, որ զննիչը ներբեռնում է այն և պահում իր [cache](https://en.wikipedia.org/wiki/Web_cache)–ում։ -Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once. +Մյուս էջերը, որոնք հղում ունեն այդ նույն սկրիպտին, նորից ներբեռնելու փոխարեն կվերցնեն այն cache–ից։ -That reduces traffic and makes pages faster. +Սա էջերը դարձնոմ է ավելի արագ և նվազեցնում է traffic–ը։ ``` -````warn header="If `src` is set, the script content is ignored." -A single ` ``` -We must choose either an external ` @@ -122,11 +122,11 @@ The example above can be split into two scripts to work: ``` ```` -## Summary +## Ամփոփում -- We can use a ``. +- Կարող ենք օգտագործել ``։ -There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many. +Այնքա՜ն բան կա սովորելու զննիչներում սկրիպտերի աշխատանքի և էջերի հետ դրանց փոխազդեցության մասին։ Հիշենք, որ ձեռնարկի այս բաժինը նվիրված է JavaScript լեզվին, այնպես որ պետք չէ ինքներս մեզ շեղենք զննիչներին հատուկ առանձնահատկություններով։ Մենք կօգտագործենք զննիչը JavaScript կոդը գործարկելու համար, ինչը հարմար է առցանց ընթերցանության համար։ diff --git a/1-js/02-first-steps/02-structure/article.md b/1-js/02-first-steps/02-structure/article.md index e81fd343d..33eede157 100644 --- a/1-js/02-first-steps/02-structure/article.md +++ b/1-js/02-first-steps/02-structure/article.md @@ -1,44 +1,44 @@ -# Code structure +# Կոդի կառուցվածքը -The first thing we'll study is the building blocks of code. +Առաջին հերթին ուսումնասիրենք կոդի կառուցման տարրական էլեմենտները։ -## Statements +## Դրույթներ (statements) -Statements are syntax constructs and commands that perform actions. +Դրույթները շարահյուսական (syntax) կառույցներ և հրամաններ են, որոնք իրականացնում են գործողություններ։ -We've already seen a statement, `alert('Hello, world!')`, which shows the message "Hello, world!". +Մենք արդեն հանդիպել են դրույթի օրինակի՝ `alert('Hello, world!')`, որի գործողությունն է ցույց տալ «Hello, world!» հաղորդագրությունը։ -We can have as many statements in our code as we want. Statements can be separated with a semicolon. +Կոդում կարող ենք ունենալ այնքան դրույթներ, որքան կամենանք։ Դրույթներն իրարից բաժանվում են կետ-ստորակետով (semicolon)։ -For example, here we split "Hello World" into two alerts: +Օրինակ՝ բաժանենք «Hello, world!»–ը երկու alert դրույթների․ ```js run no-beautify alert('Hello'); alert('World'); ``` -Usually, statements are written on separate lines to make the code more readable: +Դրույթները սովորաբար տեղադրում են առանձին տողերում՝ կոդն ավելի ընթեռնելի դարձնելու համար։ ```js run no-beautify alert('Hello'); alert('World'); ``` -## Semicolons [#semicolon] +## Կետ-ստորակետ [#semicolon] -A semicolon may be omitted in most cases when a line break exists. +Կետ-ստորակետը դեպքերի մեծամասնությունում կարելի է բաց թողել, եթե առակա է նոր տողին անցում․ -This would also work: +Հետևյալ օրինակը կաշխատի՝ ```js run no-beautify alert('Hello') alert('World') ``` -Here, JavaScript interprets the line break as an "implicit" semicolon. This is called an [automatic semicolon insertion](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion). +Այստեղ JavaScript–ն ընկալում է նոր տողին անցումը որպես կետ-ստորակետ։ Սա կոչվում է [կետ-ստորակետի ինքաշխատ ավելացում](https://tc39.github.io/ecma262/#sec-automatic-semicolon-insertion) (automatic semicolon insertion)։ -**In most cases, a newline implies a semicolon. But "in most cases" does not mean "always"!** +**Դեպքերի մեծամասնությունում նոր տողին անցումը դիտարկվում է որպես կետ-ստորակետ։ Կան դեպքեր, երբ այս պնդումը ճիշտ չէ։** -There are cases when a newline does not mean a semicolon. For example: +Որոշ դեպքերում նոր տողին անցումը չի դիտվում որպես կետ-ստորակետ։ Օրինակ՝ ```js run no-beautify alert(3 + @@ -46,14 +46,14 @@ alert(3 + + 2); ``` -The code outputs `6` because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus `"+"`, then it is an "incomplete expression", so a semicolon there would be incorrect. And in this case, that works as intended. +Կոդն արտածում է `6`, քանի որ JavaScript–ն այստեղ կետ-ստորակետ չի ավելացնում։ Ակնհայտ է․ քանի որ տողն ավարտվում է `"+"`–ով, ապա այն անավարտ արտահայտություն է և կետ–ստորակերի կարիք չկա։ -**But there are situations where JavaScript "fails" to assume a semicolon where it is really needed.** +**Կան դեպքեր, երբ JavaScript–ը կետ–ստորակետ չի դնում, բայց իրականում այն անհրաժեշտ է։** -Errors which occur in such cases are quite hard to find and fix. +Այս դեպքերում առաջացող սխալները բավական դժվար է գտնել և ուղղել։ -````smart header="An example of an error" -If you're curious to see a concrete example of such an error, check this code out: +````smart header="Սխալի օրինակ" +Ահա կոդ, որի միջոցով կհանգենք նման սխալի՝ ```js run alert("Hello"); @@ -61,9 +61,9 @@ alert("Hello"); [1, 2].forEach(alert); ``` -No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `1`, then `2`. +Այժմ չմտածենք այն մասին, թե ինչ են նշանակում `[]` փակագծերը և `forEach`–ը։ Դրանց մասին սովորելու ենք հետագայում։ Այս պահին հիշենք այս կոդի արդյունքը՝ այն արտածում է `Hello`, `1`, հետո `2`։ -Now let's remove the semicolon after the `alert`: +Հիմա եկեք `alert`-ից հետո գտնվող կետ–ստորակետը ջնջենք՝ ```js run no-beautify alert("Hello") @@ -71,85 +71,82 @@ alert("Hello") [1, 2].forEach(alert); ``` -The difference compared to the code above is only one character: the semicolon at the end of the first line is gone. +Միակ տարբերությունը բերված կոդում այդ կետ֊ստորակետն է, որն այլևս չկա։ +Եթե գործարկենք այս կոդը միայն `Hello`֊ը կարտածվի (սխալը տեսնելու համար անհրաժեշտ է բացել բարձակը)։ -If we run this code, only the first `Hello` shows (and there's an error, you may need to open the console to see it). There are no numbers any more. +Սխալն առաջանում է այն պատճառով, որ JavaScript–ը `[...]`–ից առաջ կետ–ստորակետ չի դնում։ Քանի որ կետ–ստորակետն ինքնաշխատ չի ավելացվում, այս օրինակում ողջ կոդը դիտվում է որպես մեկ դրույթ։ -That's because JavaScript does not assume a semicolon before square brackets `[...]`. So, the code in the last example is treated as a single statement. - -Here's how the engine sees it: +Ահա, թե ինչպես է JavaScript շարժիչը տեսնում այն՝ ```js run no-beautify -alert("Hello")[1, 2].forEach(alert); +alert("Սրանից հետո սխալ է լինելու")[1, 2].forEach(alert) ``` -Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly. - -This can happen in other situations also. +Պարզ է, որ այստեղ երկու դրույթ պետք է լինի՝ ոչ թե մեկ։ Դրույթների նման միաձուլումն էլ հանգեցնում է սխալին։ Սա կարող է տեղի ունենալ նաև այլ իրավիճակներում։ ```` -We recommend putting semicolons between statements even if they are separated by newlines. This rule is widely adopted by the community. Let's note once again -- *it is possible* to leave out semicolons most of the time. But it's safer -- especially for a beginner -- to use them. +Խորհուրդ ենք տալիս դրույթներից հետո դնել կետ–ստորակետ, նույնիսկ եթե դրույթներն առաձին տողերում են։ Սա տարածված կանոն է։ Եվս մեկ անգամ կրկնենք․ դեպքերի մեծամասնությունում *հնարավոր է* բաց թողել կետ–ստորակետը, բայց ավելի ապահով է (հատկապես սկսնակների համար) օգտագործել այն։ -## Comments [#code-comments] +## Մեկնաբանություններ [#code-comments] -As time goes on, programs become more and more complex. It becomes necessary to add *comments* which describe what the code does and why. +Ժամանակի ընթացքում ծրագրերի բարդությունն աճում է։ Անհրաժեշտ է լինում հաճախ *մեկնաբանությունների* միջոցով նկարագրել, թե ինչ է անում տվյալ կոդը և ինչու։ -Comments can be put into any place of a script. They don't affect its execution because the engine simply ignores them. +Մեկնաբանությունները կարող են զետեղվել սկրիպտի կամայական հատվածում։ Դրանք չեն ազդում կոդի աշխատանքի վրա, քանի որ արհամարհվում են շարժիչի կողմից։ -**One-line comments start with two forward slash characters `//`.** +**Միատող մեկնաբանությունները սկսվում են կրկնակի շեղ գծերով՝ `//`։** -The rest of the line is a comment. It may occupy a full line of its own or follow a statement. +Տողի մնացած մասը դառնում է մեկնաբանություն։ Այն կարող է զբաղեցնել ամբողջ տողը, կամ գտնվել դրույթից հետո։ -Like here: +Ինչպես հետևյալ օրինակում՝ ```js run -// This comment occupies a line of its own +// Այս մեկնաբանությունը գտնվում է առանձին տողում և զբաղեցնում է ամբողջ տողը alert('Hello'); -alert('World'); // This comment follows the statement +alert('World'); // Այս մեկնաբանությունը գտնվում է դրույթից հետո ``` -**Multiline comments start with a forward slash and an asterisk /* and end with an asterisk and a forward slash */.** +**Բազմատող մեկնաբանությունները սկսվում են շեղ գծով և աստղանիշով՝ /*, վերջանում աստղանիշով և շեղ գծով՝ */։** -Like this: +Ինչպես այս օրինակում՝ ```js run -/* An example with two messages. -This is a multiline comment. +/* Այս օրինակն արտածում է երկու հաղորդագրություն։ +Սա բազմատող մեկնաբանություն է։ */ alert('Hello'); alert('World'); ``` -The content of comments is ignored, so if we put code inside /* ... */, it won't execute. +Մեկնաբանության պարունակությունն արհամարհվում է, այնպես որ, եթե կոդ տեղադրենք /* ... */–ի մեջ, ապա այն չի գործարկվի։ -Sometimes it can be handy to temporarily disable a part of code: +Սովորաբար օգտակար է ժամանակավորապես անջատել կոդի մի մասը՝ ```js run -/* Commenting out the code +/* Այս կոդը գտնվում է մեկնաբանության մեջ և չի գործարկվի alert('Hello'); */ alert('World'); ``` -```smart header="Use hotkeys!" -In most editors, a line of code can be commented out by pressing the `key:Ctrl+/` hotkey for a single-line comment and something like `key:Ctrl+Shift+/` -- for multiline comments (select a piece of code and press the hotkey). For Mac, try `key:Cmd` instead of `key:Ctrl` and `key:Option` instead of `key:Shift`. +```smart header="Օգտագործեք ստեղների համադրություններ" +Բազմաթիվ խմբագրիչներում տողը կարելի է զետեղել մեկնաբանության մեջ, սեղմելով `key:Ctrl+/` ստեղները՝ միատող մեկնաբանության համար, և `key:Ctrl+Shift+/` ստեղները (կամ նմանատիպ այլ համադրություն)՝ բազմատող մեկնաբանությունների համար։ Mac–ում `key:Ctrl`–ի փոխարեն օգտագործեք `key:Cmd`, իսկ `key:Shift`–ի փոխարեն՝ `key:Option`։ ``` -````warn header="Nested comments are not supported!" -There may not be `/*...*/` inside another `/*...*/`. +````warn header="Մեկնաբանությունները չեն ներդրվում" +Չի կարելի ներդնել `/*...*/`–ը այլ բազմատող մեկնաբանության մեջ։ -Such code will die with an error: +Այս կոդը սխալ կառաջացնի՝ ```js run no-beautify /* - /* nested comment ?!? */ + /* ներդրված մեկնաբանություն ?!? */ */ alert( 'World' ); ``` ```` -Please, don't hesitate to comment your code. +Աշխատեք թողնել մեկնաբանություններ ձեր կոդում։ -Comments increase the overall code footprint, but that's not a problem at all. There are many tools which minify code before publishing to a production server. They remove comments, so they don't appear in the working scripts. Therefore, comments do not have negative effects on production at all. +Մեկնաբանությունները մեծացնում են սկրիպտի ծավալը, սակայն դա ընդհանրապես խնդիր չէ։ Կան բազմաթիվ գործիքներ, որոնք հնարավորինս փոքրացնում են կոդը և բերում վերջնական տեսքի՝ միչև այն սերվեր վերբեռնելը։ Դրանք ջնջում են մեկնաբանությունները, այնպես որ վերջնական սկրիպտում դրանք բացակայում են։ -Later in the tutorial there will be a chapter that also explains how to write better comments. +Այս ձեռնարկի բաժնում կանդրադառնանք այն հարցին, թե ինչպես գրել լավ մեկնաբանություններ։ diff --git a/1-js/02-first-steps/03-strict-mode/article.md b/1-js/02-first-steps/03-strict-mode/article.md index 9586733cc..93adc3598 100644 --- a/1-js/02-first-steps/03-strict-mode/article.md +++ b/1-js/02-first-steps/03-strict-mode/article.md @@ -1,58 +1,58 @@ -# The modern mode, "use strict" +# "use strict" -For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change. +Երկար ժամանակ JavaScript–ը զարգանում էր առանց համատեղելիության խնդիրների։ Լեզվում նոր հնարավորություններ էին ավելացվում, իսկ հները փոփոխության չէին ենթարկվում։ -That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript's creators got stuck in the language forever. +Այս մոտեցման առավելությունն այն էր, որ գոյություն ունեցող կոդը միշտ աշխատում էր առանց փոփոխության։ Մյուս կողմից, JavaScript–ը նախագծողների ցանկացած սխալը, կամ թերի որոշումը դատապարտված էր մնալ լեզվում ընդմիշտ։ -This was the case until 2009 when ECMAScript 5 (ES5) appeared. It added new features to the language and modified some of the existing ones. To keep the old code working, most such modifications are off by default. You need to explicitly enable them with a special directive: `"use strict"`. +Սա ճիշտ էր մինչև 2009 թ․, երբ հայտնվեց ECMAScript 5–ը (ES5)։ Այն լեզվում ավելացրեց նոր հնարավորություններ և փոփոխեց որոշ արդեն գոյություն ունեցողները։ Որպեսզի հին կոդն աշխատեր, այդ փոփոխությունները անջատած էին լռելյայն։ Դրանք պետք էր բացահայտ միացնել, օգատգործելով հատուկ հրահանգ՝ `"use strict"`։ -## "use strict" +## "use strict" հրահանգը -The directive looks like a string: `"use strict"` or `'use strict'`. When it is located at the top of a script, the whole script works the "modern" way. +Այս հրահանգն իրենից ներկայացնում է սովորական տող՝ `"use strict"`, կամ `'use strict'`։ Երբ այն գտնվում է սկրիպտի վերևում, ապա սկրիպն աշխատում է ժամանակակից ձևով։ -For example: +Օրինակ՝ ```js "use strict"; -// this code works the modern way +// այս կոդն աշխատում է ժամանակակից ձևով ... ``` -Quite soon we're going to learn functions (a way to group commands), so let's note in advance that `"use strict"` can be put at the beginning of a function. Doing that enables strict mode in that function only. But usually people use it for the whole script. +Շուտով սովորելու ենք ֆունկցիաների մասին, այնպես որ նախօրոք ասենք, որ `"use strict"`–ը կարելի է տեղադրել ֆունկցիայի սկզբում։ Դա միացնում է ժամանակակից ռեժիմը միայն այդ ֆունկցիայում։ Սովորաբար `"use strict"`–ն օգտագործվում է ողջ սկրիպտի համար։ -````warn header="Ensure that \"use strict\" is at the top" -Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled. +````warn header="Համոզվեք, որ \"use strict\"–ը գտվում է վերևում" +Համոզվեք, որ `"use strict"`–ը գտվում է սկրիպտի վերևում, հակառակ դեպքում այն կարող է չաշխատել։ -Strict mode isn't enabled here: +Այս օրինակում այն չի աշխատում՝ ```js no-strict alert("some code"); -// "use strict" below is ignored--it must be at the top +// "use strict"–ն այստեղ արհամարհվում է՝ այն պետք է գտնվի ամենավերևում "use strict"; -// strict mode is not activated +// ժամանակակից ռեժիմը միացված չէ ``` -Only comments may appear above `"use strict"`. +`"use strict"`–ից առաջ կարող են լինել միայն մեկնաբանություններ՝ ```` -```warn header="There's no way to cancel `use strict`" -There is no directive like `"no use strict"` that reverts the engine to old behavior. +```warn header="Հնարավոր չէ չեղարկել `use strict`–ի գործողությունը" +Գոյություն չունի `"no use strict"` հրահանգ, որը չեղարկում է շարժիչի պահվածքը։ -Once we enter strict mode, there's no going back. +Այսպիսով՝ `use strict`–ի գործողությունը չի կարելի չեղարկել։ ``` -## Browser console +## Զննիչի բարձակը (browser console) -When you use a [developer console](info:devtools) to run code, please note that it doesn't `use strict` by default. +[Ծրագրավորման բարձակ](info:devtools)–ում `use strict`–ը լռելյայն չի օգտագործում։ -Sometimes, when `use strict` makes a difference, you'll get incorrect results. +Երբեմն `use strict`–ի կիրառումը կարող է հանգեցնել սխալ արդյունքների։ -So, how to actually `use strict` in the console? +Ունեմն ինչպե՞ս օգտագործել `use strict`–ը բարձակում։ -First, you can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this: +Կարող եք սեղմել `key:Shift+Enter` ստեղները մի քանի տող ներմուծելու համար և գրել `use strict` վերևում՝ ```js 'use strict'; @@ -60,30 +60,26 @@ First, you can try to press `key:Shift+Enter` to input multiple lines, and put ` ``` -It works in most browsers, namely Firefox and Chrome. +Սա կաշխատի հիմնական զննիչներում (Firefox, Chrome)։ -If it doesn't, e.g. in an old browser, there's an ugly, but reliable way to ensure `use strict`. Put it inside this kind of wrapper: +Եթե օգտագործում եք շատ հին զննիչ, ապա կարելի է `use strict`–ը դնել ֆունկցիայի մեջ՝ ```js (function() { 'use strict'; - // ...your code here... + // ...ձեր կոդն այստեղ... })() ``` -## Should we "use strict"? +## Արդյոք պե՞տք է օգտագործել "use strict" հրահանգը -The question may sound obvious, but it's not so. +Պատասխանը կարող է ակնհայտ թվալ, բայց դա այդպես չէ։ -One could recommend to start scripts with `"use strict"`... But you know what's cool? +Գուցե ինչ–որ մեկը խորդուրդ տա սկսել բոլոր սկրիպտերը `"use strict"`–ով։ Սակայն, ժամանակակից JavaScript–ի «class»–երը և «module»–ները (որոնք մենք հետո կուսումնասիրենք), օգտագործում են `use strict`–ը լռելյայն։ Այնպես որ կարիք չկա օգտագործել `"use strict"` հրահանգը այդ դեպքերում։ -Modern JavaScript supports "classes" and "modules" - advanced language structures (we'll surely get to them), that enable `use strict` automatically. So we don't need to add the `"use strict"` directive, if we use them. +**Այսպիսով՝ մենք կօգտագործենք `"use strict";`–ի մեր սկրիպտերում։ Հետո, երբ ձեր կոդն ամբողջովին կգտնվի «class»–երում և «module»–ներում՝ կարող եք այն բաց թողել։** -**So, for now `"use strict";` is a welcome guest at the top of your scripts. Later, when your code is all in classes and modules, you may omit it.** +Հաջորդ բաժիններում, որտեղ կսովորենք լեզվի այլ հնարավորությունների մասին, կտեսնենք տարբերությունը `"use strict"`–ով և առանց դրա։ -As of now, we've got to know about `use strict` in general. - -In the next chapters, as we learn language features, we'll see the differences between the strict and old modes. Luckily, there aren't many and they actually make our lives better. - -All examples in this tutorial assume strict mode unless (very rarely) specified otherwise. +Այս ձեռնարկի բոլոր օրինակները ենթադրում են `"use strict"`–ի կիրառում, եթե հակառակը նշված չէ (խիստ հազվադեպ դեպքերում)։ diff --git a/1-js/02-first-steps/04-variables/1-hello-variables/solution.md b/1-js/02-first-steps/04-variables/1-hello-variables/solution.md index 9249e1c84..adc05f57c 100644 --- a/1-js/02-first-steps/04-variables/1-hello-variables/solution.md +++ b/1-js/02-first-steps/04-variables/1-hello-variables/solution.md @@ -1,7 +1,7 @@ -In the code below, each line corresponds to the item in the task list. +Ստորև բերված կոդում յուրաքանչյուր տող համապատասխանում է հանձնարարության ամեն մի կետի: ```js run -let admin, name; // can declare two variables at once +let admin, name; // կարող ենք հայտարարել միանգամից երկու փոփոխական name = "John"; diff --git a/1-js/02-first-steps/04-variables/1-hello-variables/task.md b/1-js/02-first-steps/04-variables/1-hello-variables/task.md index 84f009e8c..25b05f765 100644 --- a/1-js/02-first-steps/04-variables/1-hello-variables/task.md +++ b/1-js/02-first-steps/04-variables/1-hello-variables/task.md @@ -2,9 +2,9 @@ importance: 2 --- -# Working with variables +# Աշխատում ենք փոփոխականների հետ -1. Declare two variables: `admin` and `name`. -2. Assign the value `"John"` to `name`. -3. Copy the value from `name` to `admin`. -4. Show the value of `admin` using `alert` (must output "John"). +1. Հայտարարեք երկու փոփոխական. `admin` և `name`: +2. `name`-ին վերագրեք `"John"` արժեքը: +3. Պատճենեք `name`-ի արժեքը `admin`-ի մեջ: +4. Ցույց տվեք `admin`-ի արժեքը `alert`-ի միջոցով (պետք է արտատպի "John"): diff --git a/1-js/02-first-steps/04-variables/2-declare-variables/solution.md b/1-js/02-first-steps/04-variables/2-declare-variables/solution.md index 392f4e26f..bfafac0eb 100644 --- a/1-js/02-first-steps/04-variables/2-declare-variables/solution.md +++ b/1-js/02-first-steps/04-variables/2-declare-variables/solution.md @@ -1,21 +1,21 @@ -## The variable for our planet +## Մեր մոլորակի անունը պարունակող փոփոխականը -That's simple: +Այստեղ ամեն ինչ պարզ է՝ ```js let ourPlanetName = "Earth"; ``` -Note, we could use a shorter name `planet`, but it might not be obvious what planet it refers to. It's nice to be more verbose. At least until the variable isNotTooLong. +Կարող էինք նաև օգտագործել ավելի կարճ `planet` անունը, բայց հասկանալի չէր լինի, թե որ մոլորակի անունն է այն: Ավելի լավ է փոփոխականի անունը լինի երկար, բայց հասկանալի: Բայց ոչ շատ երկար: -## The name of the current visitor +## Տվյալ հաճախորդի անունը պահող փոփոխականը ```js let currentUserName = "John"; ``` -Again, we could shorten that to `userName` if we know for sure that the user is current. +Կարող էինք ընտրել նաև `userName` անունը, եթե հաստատ գիտենք, որ հաճախորդը տվյալ պահին կայքում է: -Modern editors and autocomplete make long variable names easy to write. Don't save on them. A name with 3 words in it is fine. +Ժամանակակից խմբագրիչները կարող են նպաստել փոփոխականների երկար անուններ գրելուն: Արժի փոփոխականի անունը պահել կարճ, ոչ ավել, քան երեք բառ: -And if your editor does not have proper autocompletion, get [a new one](/code-editors). +Եվ եթե Ձեզ խմբագրիչը չունի կոդի ինքնաշխատ հուշումներ (autocompletion) տրամադրելու հնարավորությունը, խորհուրդ ենք տալիս [փոխել այն](/code-editors): diff --git a/1-js/02-first-steps/04-variables/2-declare-variables/task.md b/1-js/02-first-steps/04-variables/2-declare-variables/task.md index f364badf4..b03486f48 100644 --- a/1-js/02-first-steps/04-variables/2-declare-variables/task.md +++ b/1-js/02-first-steps/04-variables/2-declare-variables/task.md @@ -2,7 +2,7 @@ importance: 3 --- -# Giving the right name +# Ընտրում ենք փոփոխականի ճիշտ անուն -1. Create a variable with the name of our planet. How would you name such a variable? -2. Create a variable to store the name of a current visitor to a website. How would you name that variable? +1. Հայտարարեք փոփոխական, որը կպարունակի մեր մոլորակի անունը: Ի՞նչ կդնեիք նման փոփոխականի անունը: +2. Հայտարարեք փոփոխական, որը կպարունակի կայքի տվյալ հաճախորդի անունը: Ի՞նչ կդնեիք նման փոփոխականի անունը: diff --git a/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md b/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md index acd643fde..f4de464d8 100644 --- a/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md +++ b/1-js/02-first-steps/04-variables/3-uppercast-constant/solution.md @@ -1,5 +1,5 @@ -We generally use upper case for constants that are "hard-coded". Or, in other words, when the value is known prior to execution and directly written into the code. +Ընդհանուր առմամբ մեծատառերով գրվում են այսպես կոչված «hard-coded» հաստատունները: Այլ կերպ ասած, երբ հաստատունի արժեքը նախօրոք հայտնի է մինչև կոդը գործարկելը, և այդ արժեքը ուղղակի գրված է կոդում: -In this code, `birthday` is exactly like that. So we could use the upper case for it. +Այս օրինակում `birthday`-ը պարունակում է նման արժեք, այնպես որ իմաստ ունի այն գրել մեծատառերով: -In contrast, `age` is evaluated in run-time. Today we have one age, a year after we'll have another one. It is constant in a sense that it does not change through the code execution. But it is a bit "less of a constant" than `birthday`: it is calculated, so we should keep the lower case for it. +Մյուս կողմից, `age`-ի արժեքը հայտնի է դառնում միայն երբ կոդը գործարկվում է: Տարեցտարի այդ փոփոխականի արժեքը փոխվում է: Այն հաստատուն է այն իմաստով, որ իր արժեքը չի փոխում կոդի գործարկման ժամանակ: Բայց այն «ավելի քիչ հաստատուն» է, քան `birthday`-ը, քանի որ արժեքը հաշվվում է սկրիպտի աշխատանքի ընթացքում: Այսպիսով՝ արժի գրել այն փոքրատառ: diff --git a/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md b/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md index f3c208a74..39f2eee67 100644 --- a/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md +++ b/1-js/02-first-steps/04-variables/3-uppercast-constant/task.md @@ -2,9 +2,9 @@ importance: 4 --- -# Uppercase const? +# Մեծատառ հաստատուններ -Examine the following code: +Դիտարկենք ստորև բերված կոդը՝ ```js const birthday = '18.04.1982'; @@ -12,14 +12,14 @@ const birthday = '18.04.1982'; const age = someCode(birthday); ``` -Here we have a constant `birthday` for the date, and also the `age` constant. +Այստեղ ունենք `birthday` հաստատունը, որն ամսաթիվ է պարունակում, և `age` հաստատունը։ -The `age` is calculated from `birthday` using `someCode()`, which means a function call that we didn't explain yet (we will soon!), but the details don't matter here, the point is that `age` is calculated somehow based on the `birthday`. +`age`-ը հաշվարկվում է `birthday`-ից `someCode()`-ի, ինչը նշանակում է ֆունկցիայի կանչի, ինչի մասին դեռ չենք խոսել (բայց շուտով կխոսենք)։ Այստեղ մանրամասները չենք քննարկում հակիրճության համար, կարևորն այն է, որ `age`-ը ինչ-որ կերտ հաշվարկվում է `birthday`-ի հիման վրա: -Would it be right to use upper case for `birthday`? For `age`? Or even for both? +Ճիշտ կլինե՞ր մեծատառերով գրել `birthday`-ը: Իսկ `age`-ը՞: Կամ գուցե երկու՞սն էլ: ```js -const BIRTHDAY = '18.04.1982'; // make birthday uppercase? +const BIRTHDAY = '18.04.1982'; // սա՞ գրել մեծատառերով -const AGE = someCode(BIRTHDAY); // make age uppercase? +const AGE = someCode(BIRTHDAY); // թե՞ age-ը ``` diff --git a/1-js/02-first-steps/04-variables/article.md b/1-js/02-first-steps/04-variables/article.md index e91d0ea7e..d7d389d46 100644 --- a/1-js/02-first-steps/04-variables/article.md +++ b/1-js/02-first-steps/04-variables/article.md @@ -1,61 +1,61 @@ -# Variables +# Փոփոխականներ -Most of the time, a JavaScript application needs to work with information. Here are two examples: -1. An online shop -- the information might include goods being sold and a shopping cart. -2. A chat application -- the information might include users, messages, and much more. +JavaScript ծրագրերը հաճախ աշխատում են տեղեկատվության հետ: Ահա երկու օրինակ. +1. Առցանց խանութ -- տեղեկատվության մաս են կազմում վաճառվող ապրանքները, զամբյուղը (shopping cart): +2. A chat application -- տեղեկատվությունթան մաս են կազմում օգտատերերը, հաղորդագրությունները և այլն: -Variables are used to store this information. +Փոփոխականներն օգտագործվում են այս ամենը պահելու համար: -## A variable +## Փոփոխական -A [variable](https://en.wikipedia.org/wiki/Variable_(computer_science)) is a "named storage" for data. We can use variables to store goodies, visitors, and other data. +[Փոփոխականը](https://en.wikipedia.org/wiki/Variable_(computer_science)) տվյալների «պահեստարան» է: Փոփոխականները կարելի է օգտագործել տարբեր տիպի տվյալներ պահելու համար: -To create a variable in JavaScript, use the `let` keyword. +JavaScript-ում փոփոխական ստեղծելու համար կիրառվում է `let` հիմնաբառը: -The statement below creates (in other words: *declares*) a variable with the name "message": +Ստորև բերված հայտարատությունը ստեղծում է (այլ կերպ ասած *հայտարարում է*) «message» անունով փոփոխական. ```js let message; ``` -Now, we can put some data into it by using the assignment operator `=`: +Այդ փոփոխականի մեջ որևէ տվյալ տեղադրելու համար կիրառենք վերագրման օպերատորը՝ `=`. ```js let message; *!* -message = 'Hello'; // store the string 'Hello' in the variable named message +message = 'Hello'; // տեղադրել տողը «message» անունով փոփոխականի մեջ */!* ``` -The string is now saved into the memory area associated with the variable. We can access it using the variable name: +Այդ տողն այժմ պահվում է հիշողության այն հատվածում, որը վերագրված է մեր փոփոխականին: Փոփոխականի պարունակությունը կարելի է կարդալ փոփոխականի անվան միջոցով. ```js run let message; message = 'Hello!'; *!* -alert(message); // shows the variable content +alert(message); // ցույց է տալիս փոփոխականի պարունակությունը */!* ``` -To be concise, we can combine the variable declaration and assignment into a single line: +Հակիրճ լինելու համար կհամատեղենք փոփոխականների հայտարարումն ու արժեքի վերագրումը մեկ տողում. ```js run -let message = 'Hello!'; // define the variable and assign the value +let message = 'Hello!'; // հայտատարում և արժեք ենք վերագրում փոփոխականին alert(message); // Hello! ``` -We can also declare multiple variables in one line: +Նույն տողում կարելի է հայտարարել մի քանի փոփոխականներ. ```js no-beautify let user = 'John', age = 25, message = 'Hello'; ``` -That might seem shorter, but we don't recommend it. For the sake of better readability, please use a single line per variable. +Չնայած սա կարող է հարմար թվալ, այնուամենայնիվ մենք խորհուրդ ենք տալիս յուրաքանչյուր փոփոխական հայտարարել նոր տողում: -The multiline variant is a bit longer, but easier to read: +Մի քանի տողում փոփոխականներ հայտարարելը ավելի երկար է, բայց և ավելի հեշտ է դրանք ընթեռնելը. ```js let user = 'John'; @@ -63,7 +63,7 @@ let age = 25; let message = 'Hello'; ``` -Some people also define multiple variables in this multiline style: +Երբեմն փոփոխականները հայտարարվում են հետևյալ կերպ. ```js no-beautify let user = 'John', @@ -71,7 +71,7 @@ let user = 'John', message = 'Hello'; ``` -...Or even in the "comma-first" style: +...կամ էլ այսպես: ```js no-beautify let user = 'John' @@ -79,47 +79,47 @@ let user = 'John' , message = 'Hello'; ``` -Technically, all these variants do the same thing. So, it's a matter of personal taste and aesthetics. +Սրանք բոլորն էլ նույն արդյունքն ունեն և յուրաքանչյուր ոք ընտրում է ըստ ճաշակի և նախընտրության: -````smart header="`var` instead of `let`" -In older scripts, you may also find another keyword: `var` instead of `let`: +````smart header="`var`՝ `let`-ի փոխարեն" +`let`-ի փոխարեն կարող է հանդիպել նաև `var` հիմնաբառը. ```js *!*var*/!* message = 'Hello'; ``` -The `var` keyword is *almost* the same as `let`. It also declares a variable but in a slightly different, "old-school" way. +`var` հիմնաբառը *գրեթե* նույն `let`-ն է: Այն նույնպես հայտարարում է փոփոխական, բայց կան որոշ տարբերություններ: -There are subtle differences between `let` and `var`, but they do not matter to us yet. We'll cover them in detail in the chapter . +`let`-ի և `var`-ի մեջ կան փոքր տարբերություններ, որոնք մենք դեռ չեն դիտարկի: Այդ տարբերությունների մասին մանրամասն կխոսենք բաժնում: ```` ## A real-life analogy -We can easily grasp the concept of a "variable" if we imagine it as a "box" for data, with a uniquely-named sticker on it. +Հեշտությամբ կարելի է հասկանալ «փոփոխական»-ի գաղափարը, եթե պատկերացնենք այն որպես տվյալների «արկղ», որն իրեն առանձնահատուկ պիտակ ունի: -For instance, the variable `message` can be imagined as a box labelled `"message"` with the value `"Hello!"` in it: +Օրինակ՝ `message` փոփոխականը կարելի է պատկերացնել որպես `"message"` պիտակով արկղ, որի մեջ պահվում է `"Hello!"` արժեքը: ![](variable.svg) -We can put any value in the box. +Արկղի մեջ կարող ենք դնել ցանկացած արժեք: -We can also change it as many times as we want: +Այդ արժեքները կարող ենք փոխել ըստ անհրաժեշտության. ```js run let message; message = 'Hello!'; -message = 'World!'; // value changed +message = 'World!'; // արժեքը փոխված է alert(message); ``` -When the value is changed, the old data is removed from the variable: +Երբ արժեքը փոխվում է, հին տվյալները դառնում են անհասանելի. ![](variable-change.svg) -We can also declare two variables and copy data from one into the other. +Մենք նաև կարող ենք սահմանել երկու փոփոխական և պատճենել դրանցից մեկի տվյալները մյուսի մեջ: ```js run let hello = 'Hello world!'; @@ -127,113 +127,113 @@ let hello = 'Hello world!'; let message; *!* -// copy 'Hello world' from hello into message +// պատճենել 'Hello world'-ը hello-ից message message = hello; */!* -// now two variables hold the same data +// այժմ երկու փոփոխականները պարունակում են նույն տվյալները alert(hello); // Hello world! alert(message); // Hello world! ``` -````warn header="Declaring twice triggers an error" -A variable should be declared only once. +````warn header="Նույն փոփոխականը մեկից ավել անգամ սահմանելը սխալ է առաջացնում" +Փոփոխականը կարող է սահմանվել միայն մեկ անգամ: -A repeated declaration of the same variable is an error: +Փոփոխականի հայտարարման կրկնությունը սխալ է. ```js run let message = "This"; -// repeated 'let' leads to an error +// կրկնվող 'let' հայտարարությունները առաջացնում են սխալներ let message = "That"; // SyntaxError: 'message' has already been declared ``` -So, we should declare a variable once and then refer to it without `let`. +Այսպիսով՝ մենք պետք է փոփոխականները հայտարարենք մեկ անգամ, այնուհետև օգտագործենք առանց `let` հիմնաբառի: ```` -```smart header="Functional languages" -It's interesting to note that there exist so-called [pure functional](https://en.wikipedia.org/wiki/Purely_functional_programming) programming languages, such as [Haskell](https://en.wikipedia.org/wiki/Haskell), that forbid changing variable values. +```smart header="Ֆունկցիոնալ լեզուներ" +Հետաքրքիր է իմանալ, որ գոյություն ունեն [ֆունկցիոնալ](https://hy.wikipedia.org/wiki/%D5%96%D5%B8%D6%82%D5%B6%D5%AF%D6%81%D5%AB%D5%B8%D5%B6%D5%A1%D5%AC_%D5%AE%D6%80%D5%A1%D5%A3%D6%80%D5%A1%D5%BE%D5%B8%D6%80%D5%B8%D6%82%D5%B4) ծրագրավորման լեզուներ, օրինակ՝ [Haskell](https://en.wikipedia.org/wiki/Haskell), որոնք արգելում են փոփոխականների արժեքների փոփոխությունները: -In such languages, once the value is stored "in the box", it's there forever. If we need to store something else, the language forces us to create a new box (declare a new variable). We can't reuse the old one. +Նման լեզուներում, երբ արժեքները տեղադրվում են «արկղների» դրանք այլևս փոխել հնարավոր չէ: Եթե անհրաժեշտ է պահել այլ արժեք, լեզուն ստիպում է ստեղծել նոր արկղ (հայտարարել նոր փոփոխական): -Though it may seem a little odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits. +Չնայած առաջին հայացքից այդ պահվածքը կարող է տարօրինակ թվալ, այս լեզուները իրոք օգտագործվում են լուրջ նախագծեր մշակելու համար: Ավելին, կան ոլորտներ (օր.՝ զուգահեռ հաշվարկներ), որտեղ այս սահմանափակումները շահավետ են: ``` -## Variable naming [#variable-naming] +## Փոփոխականների անվանումը [#variable-naming] -There are two limitations on variable names in JavaScript: +JavaScript-ում փոփոխականների անունների հետ կապված կա երկու սահմանափակում. -1. The name must contain only letters, digits, or the symbols `$` and `_`. -2. The first character must not be a digit. +1. Անունը պետք է պարունակի միայն տառեր, թվեր, կամ `$` և `_` նշանները: +2. Փոփոխականի անվան առաջին նշանը չպետք է լինի թիվ: -Examples of valid names: +Ստորև բերված են վավեր անունների օրինակներ. ```js let userName; let test123; ``` -When the name contains multiple words, [camelCase](https://en.wikipedia.org/wiki/CamelCase) is commonly used. That is: words go one after another, each word except first starting with a capital letter: `myVeryLongName`. +Երբ փոփոխականի անունը պարունակում է մի քանի բառեր, սովորաբար օգտագործվում է [camelCase](https://en.wikipedia.org/wiki/CamelCase): camelCase-ի օգինակ է հետևյալ անունը՝ `myVeryLongName`: -What's interesting -- the dollar sign `'$'` and the underscore `'_'` can also be used in names. They are regular symbols, just like letters, without any special meaning. +Ինչպես նշեցինք `'$'` և `'_'` նշանները ևս կարող են օգտագործվել փոփոխականների անուններում, սակայն դրանք որոշակի հատուկ իմաստ չունեն: -These names are valid: +Հետևյալ անունները վավեր են. ```js run untrusted -let $ = 1; // declared a variable with the name "$" -let _ = 2; // and now a variable with the name "_" +let $ = 1; // հայտարարել փոփոխական "$" անունով +let _ = 2; // և "_" անունով alert($ + _); // 3 ``` -Examples of incorrect variable names: +Սրանք անվավեր անունների օրինակներ են. ```js no-beautify -let 1a; // cannot start with a digit +let 1a; // փոփոխականի անունը չի կարող սկսել թվով -let my-name; // hyphens '-' aren't allowed in the name +let my-name; // գծիկները թույլատրված չեն անուններում ``` -```smart header="Case matters" -Variables named `apple` and `APPLE` are two different variables. +```smart header="Case-ը կարևոր է" +`apple` և `AppLE` անուններով փոփոխականները երկու տարբեր փոփոխականներ են: ``` -````smart header="Non-Latin letters are allowed, but not recommended" -It is possible to use any language, including Cyrillic letters, Chinese logograms and so on, like this: +````smart header="Ոչ լատիներեն տառերը թույլատրված են, բայց խորհուրդ չի տրվում դրանք օգտագործել" +Հնարավոր է օգտագործել ցանկացած լեզվի տառեր, ներառյալ կիրիլյան տառեր, չինական լոգոգրամներ, և այլն, օրինակ՝ ```js let имя = '...'; let 我 = '...'; ``` -Technically, there is no error here. Such names are allowed, but there is an international convention to use English in variable names. Even if we're writing a small script, it may have a long life ahead. People from other countries may need to read it sometime. +Այստեղ սխալ չկա։ Նման անունները վավեր են, սակայն ամենուր ընդունված է օգտագործել անգլերենը: Նույնիսկ եթե փոքր սկրիպտ եք գրում, այն հնարավոր է կարդան նաև այլազգի ծրագրավորողները: ```` -````warn header="Reserved names" -There is a [list of reserved words](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords), which cannot be used as variable names because they are used by the language itself. +````warn header="Վերապահված անուններ (reserved names)" +Գոյություն ունի [վերապահված բառերի ցանկ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords), որոնք չի կարելի օգտագործել որպես փոփոխականի անուն, քանի որ դրանք օգտագործվում են հենց լեզվի կողմից: -For example: `let`, `class`, `return`, and `function` are reserved. +Օրինակ՝ `let`, `class`, `return`, և `function` հիմնաբառերը վերապահված են: -The code below gives a syntax error: +Ստորև բերված կոդը սկալ է պարունակում. ```js run no-beautify -let let = 5; // can't name a variable "let", error! -let return = 5; // also can't name it "return", error! +let let = 5; // փոփոխականի անունը չի կարող լինել "let" +let return = 5; // ինչպես նաև "return" ``` ```` -````warn header="An assignment without `use strict`" +````warn header="Փոփոխականի վերագրումն առանց `use strict`-ի" -Normally, we need to define a variable before using it. But in the old times, it was technically possible to create a variable by a mere assignment of the value without using `let`. This still works now if we don't put `use strict` in our scripts to maintain compatibility with old scripts. +Սովորաբար փոփոխականներն օգտագործելուց առաջ պետք է դրանք հայտարարել: Նախկինում հնարավոր էր ստեղծել փոփոխական միայն վերագրման միջոցով՝ առանց օգտագործելու `let`-ը: Դա այժմ ևս հնարավոր է, եթե սկրիպտում չլինի `use strict`-ը: ```js run no-strict -// note: no "use strict" in this example +// ուշադրություն դրաձրեք, որ այս սկրիպտում "use strict" չկա -num = 5; // the variable "num" is created if it didn't exist +num = 5; // "num" փոփոխականը ստեղծվում է, եթե այն գոյություն չուներ alert(num); // 5 ``` -This is a bad practice and would cause an error in strict mode: +Սա սխալ է առաջացնում «strict mode»-ում. ```js "use strict"; @@ -244,15 +244,15 @@ num = 5; // error: num is not defined ``` ```` -## Constants +## Հաստատուններ -To declare a constant (unchanging) variable, use `const` instead of `let`: +Հաստատուն սահմանելու համար `let`-ի փոխարեն օգտագործեք `const`. ```js const myBirthday = '18.04.1982'; ``` -Variables declared using `const` are called "constants". They cannot be reassigned. An attempt to do so would cause an error: +`const`-ով սահմանված փոփոխականները կոչվում են «հաստատուններ». դրանց չի կարելի նոր արժեք վերագրել: Նման փորձը սխալի կհանգեցնի. ```js run const myBirthday = '18.04.1982'; @@ -260,15 +260,15 @@ const myBirthday = '18.04.1982'; myBirthday = '01.01.2001'; // error, can't reassign the constant! ``` -When a programmer is sure that a variable will never change, they can declare it with `const` to guarantee and communicate that fact to everyone. +Եթե վստահ եք, որ փոփոխականի արժեքը երբեր չի փոխվի, սահմանեք այն որպես `const` դա ապահովելու և բոլորին այդ փաստն ակնհայտ դարձնելու համար: -### Uppercase constants +### Մեծատառ հաստատուններ -There is a widespread practice to use constants as aliases for difficult-to-remember values that are known before execution. +Ընդունված է հաստատունները օգտագործել դժվար հիշվող արժեքների համար, որոնք հայտնի են նախօրոք: -Such constants are named using capital letters and underscores. +Նման հաստատունները գրվում են մեծատառ և ընդգծիկներով (underscores): -For instance, let's make constants for colors in so-called "web" (hexadecimal) format: +Օրինակ՝ սահմանենք հաստատուններ որոշ գույների համար. ```js run const COLOR_RED = "#F00"; @@ -276,70 +276,70 @@ const COLOR_GREEN = "#0F0"; const COLOR_BLUE = "#00F"; const COLOR_ORANGE = "#FF7F00"; -// ...when we need to pick a color +// ...գույնն օգտագործելու համար let color = COLOR_ORANGE; alert(color); // #FF7F00 ``` -Benefits: +Առավելությունները. -- `COLOR_ORANGE` is much easier to remember than `"#FF7F00"`. -- It is much easier to mistype `"#FF7F00"` than `COLOR_ORANGE`. -- When reading the code, `COLOR_ORANGE` is much more meaningful than `#FF7F00`. +- `COLOR_ORANGE`-ը շատ ավելի հեշտ է մտապահել, քան `"#FF7F00"`-ը, +- ավելի հեշտ է սխալ գրել `"#FF7F00"`-ը, քան `COLOR_ORANGE`-ը, +- կոդը կարդալիս `COLOR_ORANGE`-ն ավելի շատ իմաստ է արտահայտում, քան `#FF7F00`-ը: -When should we use capitals for a constant and when should we name it normally? Let's make that clear. +Եկեք հասկանանք երբ է պետք հաստատունները գրել մեծատառերով, իսկ երբ ոչ: -Being a "constant" just means that a variable's value never changes. But some constants are known before execution (like a hexadecimal value for red) and some constants are *calculated* in run-time, during the execution, but do not change after their initial assignment. +«Հաստատունն» ուղղակի փոփոխական է, որի արժեքը չի փոխվում: Կան հաստատուններ, որոնց արժեքը հայտնի է մինչև սկրիպտը գործարկելը (ինչպես, օրինակ, վերոնշյալ գույները) և կան հաստատուններ, որոնց արժեքը հայտնի է դառնում միայն սկրիպտի աշխատանքի ընթացքում և այն չի փոխվում սկզբնական վերագրումից հետո: -For instance: +Օրինակ՝ ```js const pageLoadTime = /* time taken by a webpage to load */; ``` -The value of `pageLoadTime` is not known before the page load, so it's named normally. But it's still a constant because it doesn't change after the assignment. +`pageLoadTime`-ի արժեքը հայտնի չէ, քանի դեռ էջն ամբողջությամբ չի բեռնվել, այդ իսկ պատճառով այն մեծատառ չէ։ Սակայն այն հաստատուն է, քանի որ վերագրելուց հետո արժեքը չի փոխվում: -In other words, capital-named constants are only used as aliases for "hard-coded" values. +Այլ կերպ ասած՝ մեծատառերով գրված հաստատունները օգտագործվում են միայն որպես «կոշտ կոդավորված» արժեքների փոխանուններ: -## Name things right +## Ճիշտ անունների ընտրությունը կարևոր է -Talking about variables, there's one more extremely important thing. +Երբ խոսում ենք փոփոխականների մասին մի կարևոր բան կա, որը պետք է միշտ հիշել: -A variable name should have a clean, obvious meaning, describing the data that it stores. +Փոփոխականը պետք է ունենա պարզ, միարժեք հասկանալի, և պարունակող արժեքը բնութագրող անուն: -Variable naming is one of the most important and complex skills in programming. A glance at variable names can reveal which code was written by a beginner versus an experienced developer. +Փոփոխականները անվանելը կարևորագույն և դժվար ունակություններից է ծրագրավորման մեջ: Արագ նայելով փոփոխականնրի անուններին կարելի է կարծիք կազվել կոդը գրած ծրագրավորողի ունակությունների մասին: -In a real project, most of the time is spent modifying and extending an existing code base rather than writing something completely separate from scratch. When we return to some code after doing something else for a while, it's much easier to find information that is well-labelled. Or, in other words, when the variables have good names. +Իրական նախագծերում հիմնական ժամանակը ծախսվում է գոյություն ունեցող կոդը փոփոխելու և զարգացնելու վրա: Երբ վերադառնում ենք մեր գրած կոդին որոշ ժամանակ հետո շատ ավելի հեշտ է վերհիշել այն, երբ փոփոխականներն իմաստավոր անուններ ունեն: -Please spend time thinking about the right name for a variable before declaring it. Doing so will repay you handsomely. +Հորդորում ենք ծախսել որոշ ժամանակ մտածելու ճիշտ անուններ փոփոխականների համար մինչև դրանք հայտարարելը: Հավատացեք, դա Ձեզ հետագայում միայն կօգնի: -Some good-to-follow rules are: +Ահա որոշ կանոններ, որոնց արժի հետևել. -- Use human-readable names like `userName` or `shoppingCart`. -- Stay away from abbreviations or short names like `a`, `b`, and `c`, unless you know what you're doing. -- Make names maximally descriptive and concise. Examples of bad names are `data` and `value`. Such names say nothing. It's only okay to use them if the context of the code makes it exceptionally obvious which data or value the variable is referencing. -- Agree on terms within your team and in your mind. If a site visitor is called a "user" then we should name related variables `currentUser` or `newUser` instead of `currentVisitor` or `newManInTown`. +- օգտագործեք հեշտ ընթեռնելի անուններ, օրինակ՝ `userName`, կամ `shoppingCart`, +- մի օգտագործեք հապավումներ կամ նմանատիպ կարճ անուններ՝ `a`, `b`, `c`, եթե, իհարկե, գիտեք ինչ եք ունում, +- անուններն ընտրեք հնարավորինս նկարագրող և հակիրճ: `data`-ն և `value`-ն վատ անունների օրինակներ են, քանի որ նման անունները ոչինչ չեն ասում: Նման անունները կարելի է միայն օգտագործել այն դեպքերում, երբ կոդի համատեքստը (context) միանշանակ հասկանալի է դարձնում, թե ինչ արժեքներ են այդ փոփոխականները պարունակում, +- եկեք համաձայնության Ձեր թիմով, կամ ինքներդ Ձեզ հետ: Եթե Ձեր կայքի հաճախորդին անվանում եք «user», ապա նրա հետ կապված փոփոխականները պետք է ունենան նմանատիպ անուններ՝ `currentUser`, կամ `newUser` և ոչ թե `currentVisitor`, կամ `newManInTown`: -Sounds simple? Indeed it is, but creating descriptive and concise variable names in practice is not. Go for it. +Այս ամենը պարզ է հնչում, սակայն գործնականում հասկանալի և հակիրճ փոփոխականների անուններ մտածելն այնքան էլ հեշտ չէ: Ինքներդ փորձեք և կհամոզվեք: -```smart header="Reuse or create?" -And the last note. There are some lazy programmers who, instead of declaring new variables, tend to reuse existing ones. +```smart header="Օգտագործե՞լ եղած փոփոխականը, թե՞ նորը մտածել" +Որոշ ծույլ ծրագրավորողներ փորձում են կրկին օգտագործել հայտարարած փոփոխականները՝ նորերը սահմանելու փոխարեն: -As a result, their variables are like boxes into which people throw different things without changing their stickers. What's inside the box now? Who knows? We need to come closer and check. +Արդյունքում նրանց փոփոխականները նմանվում են արկղերի, որոնց մեջ տարբեր տիպի իրեր են նետվում, առանց արկի պիտակը փոխելու: Այպես դժվարանում է հասկանալ, թե ինչ է պահվում այդ արկղում: -Such programmers save a little bit on variable declaration but lose ten times more on debugging. +Նման դեպքերում ծրագրավորողները մի փոքր խնայում են փոփոխականները հայտարարելիս, սակայն ավելի շատ ժամանակ են ծախսում, երբ խնդիրներ են առաջանում: -An extra variable is good, not evil. +Այսպիսով՝ ավել փոփոխականը վատ բան չէ: -Modern JavaScript minifiers and browsers optimize code well enough, so it won't create performance issues. Using different variables for different values can even help the engine optimize your code. +Ժամանակակից JavaScript-ում կան գործիքներ, որոնք փոքրացնում և լավարկում (optimize) են կոդն այն աստիճան, որ ավել փոփոխականներ ունենալը խնդիրներ չի առաջացնի: Նույնիսկ հակառակը. տարբեր արժեքները տարբեր փոփոխականներում պահելը կարող է օգնել շարժիչին այս գործը կատարելիս: ``` -## Summary +## Ամփոփում -We can declare variables to store data by using the `var`, `let`, or `const` keywords. +Տվյալները պահելու համար կարող ենք հայտարարել փոփոխականներ, օգտագործելով `var`, `let`, կամ `const` հիմնաբառերը: -- `let` -- is a modern variable declaration. -- `var` -- is an old-school variable declaration. Normally we don't use it at all, but we'll cover subtle differences from `let` in the chapter , just in case you need them. -- `const` -- is like `let`, but the value of the variable can't be changed. +- `let` -- ներկայումս փոփոխականները հայտարարվում են այս հիմնաբառով: +- `var` -- նախկինում օգտագործվում էր փոփոխականներ հայտարարելու համար: Այժմ այն չենք օգտագործում, իսկ սրա և `let`-ի տարբերությունները կքննարկենք բաժնում: +- `const` -- նման է `let`-ին, սակայն այս հիմնաբառով հայտարարված փոփոխականի արժեքը չի փոխվում: -Variables should be named in a way that allows us to easily understand what's inside them. +Փոփոխականների անունները պետք է պարզ հուշեն, թե ինչ արժեք է պարունակում տվյալ փոփոխականը։ diff --git a/1-js/02-first-steps/05-types/1-string-quotes/solution.md b/1-js/02-first-steps/05-types/1-string-quotes/solution.md index 68a13c15b..90f3892a7 100644 --- a/1-js/02-first-steps/05-types/1-string-quotes/solution.md +++ b/1-js/02-first-steps/05-types/1-string-quotes/solution.md @@ -1,15 +1,15 @@ -Backticks embed the expression inside `${...}` into the string. +Թեք չակերտները ներառում են `${...}`-ի մեջ գրված արտահայտության արդյունքը տողի մեջ։ ```js run -let name = "Ilya"; +let name = "David"; -// the expression is a number 1 +// արտահայտությունը 1 թիվն է alert( `hello ${1}` ); // hello 1 -// the expression is a string "name" +// արտահայտությունը "name" տողն է alert( `hello ${"name"}` ); // hello name -// the expression is a variable, embed it -alert( `hello ${name}` ); // hello Ilya +// արտահայտությունը փոփոխական, ներդնենք այն +alert( `hello ${name}` ); // hello David ``` diff --git a/1-js/02-first-steps/05-types/1-string-quotes/task.md b/1-js/02-first-steps/05-types/1-string-quotes/task.md index 14ea6b4d6..07005f96c 100644 --- a/1-js/02-first-steps/05-types/1-string-quotes/task.md +++ b/1-js/02-first-steps/05-types/1-string-quotes/task.md @@ -2,16 +2,16 @@ importance: 5 --- -# String quotes +# Տողի չակերտները -What is the output of the script? +Ինչպիսի՞ն կլինի սկրիպտի արտաբերած արդյունքը։ ```js -let name = "Ilya"; +let name = "David"; alert( `hello ${1}` ); // ? alert( `hello ${"name"}` ); // ? alert( `hello ${name}` ); // ? -``` \ No newline at end of file +``` diff --git a/1-js/02-first-steps/05-types/article.md b/1-js/02-first-steps/05-types/article.md index 04e8b2450..6c9d88c6b 100644 --- a/1-js/02-first-steps/05-types/article.md +++ b/1-js/02-first-steps/05-types/article.md @@ -1,225 +1,237 @@ -# Data types +# Տվյալների տիպերը -A value in JavaScript is always of a certain type. For example, a string or a number. +JavaScript-ում արժեքը միշտ պատկանում է տվյալների որոշակի տիպի։ Օրինակ՝ տող (string) կամ թիվ (number)։ -There are eight basic data types in JavaScript. Here, we'll cover them in general and in the next chapters we'll talk about each of them in detail. +JavaScript-ում կան տվյալների ութ հիմնական տիպեր։ Այս գլխում մենք կանրադառնանք դրանց մասնակիորեն, իսկ հաջորդ գլուխներում կխոսենք դրանցից յուրաքանչյուրի մասին ավելի մանրամասն։ -We can put any type in a variable. For example, a variable can at one moment be a string and then store a number: +Փոփոխականը կարող է պարունակել ցանկացած տիպի տվյալ։ Օրինակ՝ սկզբում այն կարող է պարունակել տող (string), իսկ հետո՝ փոխարինվել թվով (number)․ ```js -// no error -let message = "hello"; +// Սխալ չկա +let message = "բարև"; message = 123456; ``` -Programming languages that allow such things, such as JavaScript, are called "dynamically typed", meaning that there exist data types, but variables are not bound to any of them. +Այն լեզուները, որոնք թույլ են տալիս նման պահվածք, կոչվում են «դինամիկ տիպավորված»։ Դա նշանակում է, որ տիպերը գոյություն ունեն, բայց փոփոխականները կապված չեն դրանցից ոչ մեկի հետ։ -## Number +## Թիվ (Number) ```js let n = 123; n = 12.345; ``` -The *number* type represents both integer and floating point numbers. +*number* տիպը ներկայացնում է ինչպես ամբողջ թվերը, այնպես էլ տասնորդական թվերը։ -There are many operations for numbers, e.g. multiplication `*`, division `/`, addition `+`, subtraction `-`, and so on. +Թվերի համար գոյություն ունեն բազմաթիվ գործողություններ, օրինակ՝ բազմապատկում `*`, բաժանաում `/`, գումարում `+`, հանում `-` և այլն. -Besides regular numbers, there are so-called "special numeric values" which also belong to this data type: `Infinity`, `-Infinity` and `NaN`. +Բացի սովորական թվերից կան նաև այսպես կոչված «հատուկ թվային արժեքներ», որոնք նույնպես պատկանում են այս տվյալների տիպին․ `Infinity`, `-Infinity` և `NaN`։ -- `Infinity` represents the mathematical [Infinity](https://en.wikipedia.org/wiki/Infinity) ∞. It is a special value that's greater than any number. +- `Infinity`-ն ներկայացնում է մաթեմատիկական [անվերջությունը](https://hy.wikipedia.org/wiki/%D4%B1%D5%B6%D5%BE%D5%A5%D6%80%D5%BB%D5%B8%D6%82%D5%A9%D5%B5%D5%B8%D6%82%D5%B6_(%D5%B4%D5%A1%D5%A9%D5%A5%D5%B4%D5%A1%D5%BF%D5%AB%D5%AF%D5%A1)) ∞։ Այն հատուկ արժեք է, որը մեծ է ցանկացած թվից։ - We can get it as a result of division by zero: + Մենք կարող ենք ստանալ այն որպես զրոյի վրա բաժանման արդյունք, ```js run alert( 1 / 0 ); // Infinity ``` - Or just reference it directly: + կամ վերցնելով այն ակնհայտ կերպով։ ```js run alert( Infinity ); // Infinity ``` -- `NaN` represents a computational error. It is a result of an incorrect or an undefined mathematical operation, for instance: +- `NaN`-ը նշանակում է հաշվողական սխալ։ Այն սխալ կամ անորոշ մաթեմատիկական գործողույան արդյունք է, օրինակ․ ```js run - alert( "not a number" / 2 ); // NaN, such division is erroneous + alert( "ոչ թվային արժեք" / 2 ); // NaN, բաժանումը հնարավոր չէ ``` - `NaN` is sticky. Any further mathematical operation on `NaN` returns `NaN`: + `NaN`-ը անփոփոխ արժեք է։ Ցանկացած գործողություն `NaN`-ի հետ վերադարձնում է `NaN`: ```js run alert( NaN + 1 ); // NaN alert( 3 * NaN ); // NaN - alert( "not a number" / 2 - 1 ); // NaN + alert( "ոչ թվային արժեք" / 2 - 1 ); // NaN ``` - So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result (there's only one exception to that: `NaN ** 0` is `1`). + Եթե մաթեմատիկական արտահայտության որևէ անդամ `NaN` է, ապա ամբողջ արտահայտության արդյունքը կլինի `NaN`։ Միակ բացառությունը `NaN ** 0` = `1` է։ -```smart header="Mathematical operations are safe" -Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc. +```smart header="Մաթեմատիկական գործողությունները անվտանգ են" +Մաթեմատիկական գործողությունները JavaScript-ում «անվտանգ» են։ Մենք կարող ենք կատարել ցանկացած գործողություն՝ բաժանել զրոյի, ոչ թվային տողերի հետ վարվել ինչպես թվերի հետ։ -The script will never stop with a fatal error ("die"). At worst, we'll get `NaN` as the result. +Սկրիպտը երբեք կանգ չի առնի՝ շպրտելով սխալ։ Վատագույն դեպքում, որպես արդյունք, մենք կստանանք `NaN`։ ``` -Special numeric values formally belong to the "number" type. Of course they are not numbers in the common sense of this word. +Հատուկ թվային արժեքները պատկանում են «թիվ» (number) տիպին։ Իրականում դրանք թվեր չեն բառի ուղիղ իմաստով: -We'll see more about working with numbers in the chapter . +Թվերի հետ աշխատանքին ավելի մանրամասն կծանոթանանք գլխում։ ## BigInt [#bigint-type] -In JavaScript, the "number" type cannot safely represent integer values larger than (253-1) (that's `9007199254740991`), or less than -(253-1) for negatives. +JavaScript-ում «number» տիպը չի կարող ներկայացնել թվային արժեքներ, որոնք մեծ են (253-1)-ից (նույնն է, ինչ `9007199254740991`), կամ փոքր են -(253-1)-ից՝ բացասական թվերի դեպքում։ -To be really precise, the "number" type can store larger integers (up to 1.7976931348623157 * 10308), but outside of the safe integer range ±(253-1) there'll be a precision error, because not all digits fit into the fixed 64-bit storage. So an "approximate" value may be stored. +Իսկապես ճշգրիտ լինելու համար, «number» տիպը կարող է պահել ավելի մեծ ամբողջ թվեր (մինչև 1.7976931348623157 * 10308), բայց անվտանգ ամբողջ թվերի միջակայքից դուրս ±(2): 53-1) ճշգրտության սխալ կլինի, քանի որ ոչ բոլոր թվանշաններն են տեղավորվում ֆիքսված 64-բիթանոց պահեստում: Այնպես որ, «մոտավոր» արժեք կարող է պահվել: -For example, these two numbers (right above the safe range) are the same: +Օրինակ, այս երկու թվերը (անվտանգ տիրույթից անմիջապես վերև) նույնն են. ```js console.log(9007199254740991 + 1); // 9007199254740992 console.log(9007199254740991 + 2); // 9007199254740992 ``` -So to say, all odd integers greater than (253-1) can't be stored at all in the "number" type. +Այսպես ասած՝ (253-1)-ից մեծ բոլոր կենտ ամբողջ թվերն ընդհանրապես չեն կարող պահվել «number» տիպում։ -For most purposes ±(253-1) range is quite enough, but sometimes we need the entire range of really big integers, e.g. for cryptography or microsecond-precision timestamps. +Շատ նպատակների համար ±(253-1) միջակայքը բավական է, բայց երբեմն մեզ անհրաժեշտ է իսկապես մեծ ամբողջ թվերի ամբողջ միջակայքը, օրինակ. գաղտնագրության կամ միկրովայրկյանային ճշգրտությամբ ժամանակի համար: -`BigInt` type was recently added to the language to represent integers of arbitrary length. +`BigInt`-ը վերջերս է ավելացվել լեզվում՝ կամայական մեծության թվեր նեկայացնելու նպատակով։ -A `BigInt` value is created by appending `n` to the end of an integer: +`BigInt` արժեք ստեղծվում է թվին վերջից կցելով `n`․ ```js -// the "n" at the end means it's a BigInt +// «n»-ը վերջում նշանակում է, որ արժեքը BigInt տիպի է const bigInt = 1234567890123456789012345678901234567890n; ``` -As `BigInt` numbers are rarely needed, we don't cover them here, but devoted them a separate chapter . Read it when you need such big numbers. +Քանի որ `BigInt` թվերը հազվադեպ են օգտագործվում, դրանց այստեղ չենք անդրադառնա, այլ կդիտարկենք առանձին՝ գլխում։ Կարդացե՛ք այն, եթե նման մեծ թվերի օգտագոծման կարիք կունենաք։ +<<<<<<< HEAD + +```smart header="Համատեղելիության խնդիրներ" +Այս պահին `BigInt`-ը համատեղելի է Firefox/Chrome/Edge/Safari զննիչների հետ, բայց ոչ IE-ի։ +``` + +Կարող եք ստուգել [*MDN* BigInt compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) հոդվածը, հասկանալու համար, թե զննիչների որ տարբերակների հետ է այն համատեղելի։ + +## Տող (String) +======= ## String +>>>>>>> 035c5267ba80fa7b55878f7213cbde449b4092d9 -A string in JavaScript must be surrounded by quotes. +JavaScript-ում տողը պետք է շրջապատված լինի չակերտներով։ ```js -let str = "Hello"; -let str2 = 'Single quotes are ok too'; -let phrase = `can embed another ${str}`; +let str = "Բարև"; +let str2 = 'Եզակի չակերտները նույպես թույլատրելի են'; +let phrase = `թեք չակերտները կարող են ներառել փոփոխականներ ${str}`; ``` -In JavaScript, there are 3 types of quotes. +JavaScript-ում գոյություն ոնեն 3 տեսակի չակերտներ. -1. Double quotes: `"Hello"`. -2. Single quotes: `'Hello'`. -3. Backticks: `Hello`. +1. Կրկնակի չակերտներ․ `"Բարև"`։ +2. Եզակի չակերտներ․ `'Բարև'`։ +3. Թեք չակերտներ․ `Բարև`։ -Double and single quotes are "simple" quotes. There's practically no difference between them in JavaScript. +Կրկնակի և եզակի չակերտները «պարզ» չակերտներ են։ JavaScript-ում դրանց միջև տարբերություններ չկան։ -Backticks are "extended functionality" quotes. They allow us to embed variables and expressions into a string by wrapping them in `${…}`, for example: +Թեք չակերտները ունեն «ընդլայնված ֆունկցիոնալություն»։ Դրանք թույլ են տալիս ներդնել փոփոխականներ և արտահայտություններ տողի մեջ՝ դրանք `${…}`-ի մեջ պարփակելու միջոցով, օրինակ․ ```js run -let name = "John"; +let name = "Դավիթ"; -// embed a variable -alert( `Hello, *!*${name}*/!*!` ); // Hello, John! +// ներդնենք փոփոխականը +alert( `Բարև, *!*${name}*/!*!` ); // Բարև, Դավիթ! -// embed an expression -alert( `the result is *!*${1 + 2}*/!*` ); // the result is 3 +// ներդնենք արտահայտություն +alert( `արդյունքը կլինի *!*${1 + 2}*/!*` ); // արդյունքը կլինի 3 ``` -The expression inside `${…}` is evaluated and the result becomes a part of the string. We can put anything in there: a variable like `name` or an arithmetical expression like `1 + 2` or something more complex. +`${…}`-ի մեջ ներդրված արտահայտությունը գնահատվում է, և արդյունքը դառնում է տողի մի մասը։ Մենք կարող ենք տեղադրել այնտեղ ամեն ինչ՝ փոփոխական (`name`) կամ թվաբանական արտահայտություն՝ `1 + 2`-ի նման կամ ավելի բարդ։ + +Ուշադրություն դարձրեք այն փաստին, որ սա հնարավոր է միայն թեք չակերտների դեպքում։ Մյուս չակերտները չունեն այսպիսի ներդրման ֆունկցիոնալություն։ -Please note that this can only be done in backticks. Other quotes don't have this embedding functionality! ```js run -alert( "the result is ${1 + 2}" ); // the result is ${1 + 2} (double quotes do nothing) +alert( "արդյունքը կլինի ${1 + 2}" ); // արդյունքը կլինի ${1 + 2} (կրկնակի չակերտները ոչինչ չեն անում) ``` -We'll cover strings more thoroughly in the chapter . +Մենք կանրադառնանք տողերին ավելի մանրամասն գլխում։ -```smart header="There is no *character* type." -In some languages, there is a special "character" type for a single character. For example, in the C language and in Java it is called "char". +```smart header="Գոյություն չունի *character* տիպ։" +Որոշ լեզուներում գոյություն ունի հատուկ "character" տիպ եզակի սիմվոլների համար։ Օրինակ՝ C և Java լեզուներում այն կոչվում է «char»։ -In JavaScript, there is no such type. There's only one type: `string`. A string may consist of zero characters (be empty), one character or many of them. +JavaScript-ում չկա նման տիպ։ Կա միայն մեկ տիպ՝ `string`։ string-ը կարող է լինել դատարկ, ունենալ մեկ կամ բազմաթիվ նիշեր։ ``` -## Boolean (logical type) +## Boolean (տրամաբանական տիպ) -The boolean type has only two values: `true` and `false`. +Boolean տիպը ունի երկու արժեք․ `true` և `false`։ -This type is commonly used to store yes/no values: `true` means "yes, correct", and `false` means "no, incorrect". +Այս տիպը հիմնականում օգտագործվում է այո/ոչ արժեքներ պահելու համար․ `true` նշանակում է «այո, ճիշտ է», իսկ `false` նշանակում է «ոչ, սխալ է»։ -For instance: +Օրինակ՝ ```js -let nameFieldChecked = true; // yes, name field is checked -let ageFieldChecked = false; // no, age field is not checked +let nameFieldChecked = true; // այո, անվանական դաշտը ստուգված է +let ageFieldChecked = false; // ոչ, տարիքային դաշտը ստուգված չէ ``` -Boolean values also come as a result of comparisons: +Boolean արժեքները ստացվում են նաև որպես համեմատությունների արդյունք․ ```js run let isGreater = 4 > 1; -alert( isGreater ); // true (the comparison result is "yes") +alert( isGreater ); // true (համեմատության արդյունքն է «այո») ``` -We'll cover booleans more deeply in the chapter . +Մենք կանրադառնանք boolean տիպին ավելի մանրամասն գլխում։ -## The "null" value +## «null» արժեքը -The special `null` value does not belong to any of the types described above. +`null` հատուկ արժեքը չի պատկանում վերոնշյալ տիպերից ոչ մեկին։ -It forms a separate type of its own which contains only the `null` value: +Այն ձևավորում է առանձին տիպ, որը պարունակում է `null` արժեքը: ```js let age = null; ``` -In JavaScript, `null` is not a "reference to a non-existing object" or a "null pointer" like in some other languages. +JavaScript-ում `null`-ը «գոյություն չունեցող օբյեկտի հղում» կամ «զրոյական ցուցիչ» չէ, ինչպես որոշ այլ լեզուներում։ -It's just a special value which represents "nothing", "empty" or "value unknown". +Այն պարզապես հատուկ արժեք է, որը նշանակում է «ոչինչ», «դատարկություն» կամ «անհայտ արժեք»։ -The code above states that `age` is unknown. +Վերոնշյալ կոդը պնդում է, որ `age` փոփոխականի արժեքը անհայտ է։ -## The "undefined" value +## «undefined» արժեքը -The special value `undefined` also stands apart. It makes a type of its own, just like `null`. +`undefined` հատուկ արժեքը նույնպես ուրույն է։ Այն ձևավորում է իր սեփական տիպը, ճիշտ ինչպես `null`-ը։ -The meaning of `undefined` is "value is not assigned". +`undefined` նշանակում է, որ «արժեք չի վերագրվել»։ -If a variable is declared, but not assigned, then its value is `undefined`: +Եթե փոփոխականը հայտարարված է, բայց նրան արժեք չի վերագրվել, ապա նրա արժեքը կլինի `undefined`․ ```js run let age; -alert(age); // shows "undefined" +alert(age); // ցույց կտա «undefined» ``` -Technically, it is possible to explicitly assign `undefined` to a variable: +Տեխնիկապես փոփոխականին հնարավոր է ակնհայտ կերպով վերագրել `undefined` արժեքը․ ```js run let age = 100; -// change the value to undefined +// արժեքը դարձնել «undefined» age = undefined; -alert(age); // "undefined" +alert(age); // «undefined» ``` -...But we don't recommend doing that. Normally, one uses `null` to assign an "empty" or "unknown" value to a variable, while `undefined` is reserved as a default initial value for unassigned things. +...Բայց խորհուրդ չի տրվում այդպես անել։ Սովորաբար `null`-ը օգտագործվում է փոփոխականին «դատարկ» կամ «անհայտ» արժեք վերագրելու համար, մինչդեռ `undefined`-ը իրենից ենթադրում է նախնական լռելյայն (default) արժեք՝ չվերագրված փոփոխականների համար։ -## Objects and Symbols +## Օբյեկտներ և սիմվոլներ -The `object` type is special. +`object` տիպը յուրահատուկ է։ -All other types are called "primitive" because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities. +Մնացած բոլոր տիպերը կոչվում են «պրիմիտիվ» տիպեր, քանի որ նրանց արժեքները պարզ արժեքներ են (լինի այն տող, թիվ կամ այլ արժեք)։ Օբյեկտները, իրենց հերթին, օգտագործվում են տվյալների համախումբ և ավելի բարդ կառուցվածքներ պահեստավորելու նպատակով։ -Being that important, objects deserve a special treatment. We'll deal with them later in the chapter , after we learn more about primitives. +Օբյեկտները լեզվում կարևոր տեղ են զբաղեցնում և հատուկ ուշադրության են արժանի։ Մենք կզբաղվենք դրանցով ավելի ուշ՝ գլխում՝ պրիմիտիվ տիպերը ավելի խորը ուսումնասիրելուց հետո։ -The `symbol` type is used to create unique identifiers for objects. We have to mention it here for the sake of completeness, but also postpone the details till we know objects. +`symbol` տիպը օգտագործվում է օբյեկտներում չկրկնվող նույնացուցիչներ ստեղծելու համար։ Մենք այստեղ նշում ենք դրա գոյության փաստը՝ տիպերի նկարագիրը լիարժեք դարձնելու համար, բայց թողնում ենք դրա ուսումնասիրությունը հետագայի համար, երբ արդեն ուսումնասիրած կլինենք օբյեկտները։ -## The typeof operator [#type-typeof] +## typeof օպերատորը [#type-typeof] -The `typeof` operator returns the type of the operand. It's useful when we want to process values of different types differently or just want to do a quick check. +`typeof` օպերատորը վերադարձնում է իր արգումենտի տիպը։ Այն օգտակար է, երբ մենք ուզում ենք մշակել տարբեր տիպերի արժեքները տարբեր կերպով, կամ պարզապես արագ ստուգում անել -A call to `typeof x` returns a string with the type name: +`typeof x`-ի կանչը վերադարձնում է տող, որը պարունակում է տիպի անվանումը․ ```js typeof undefined // "undefined" @@ -247,11 +259,11 @@ typeof alert // "function" (3) */!* ``` -The last three lines may need additional explanation: +Վերջին երեք տողերը ունեն հավելյալ պարզաբանման կարիք․ -1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter . Here, it serves just as an example of an object. -2. The result of `typeof null` is `"object"`. That's an officially recognized error in `typeof`, coming from very early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own. The behavior of `typeof` is wrong here. -3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That also comes from the early days of JavaScript. Technically, such behavior isn't correct, but can be convenient in practice. +1. `Math`-ը ներկառուցված օբյեկտ է, որը տրամադրում է մաթեմատիկական տարբեր գործողություններ և հաստատուններ։ Մենք կուսումնասիրենք այն գլխում։ Այստեղ այն պարզապես ծառայում է որպես օբյեկտի օրինակ։ +2. `typeof null`-ի արդյունքը `"object"` է։ Այն `typeof` օպերատորի վարքագծի պաշտոնապես ընդունված սխալ է, որը եկել է JavaScript-ի ստեղծման վաղ ժամանակներից և մնացել է լեզվում համատեղելիության նպատակով։ Անշուշտ, `null`-ը օբյեկտ չէ։ Այն հատուկ արժեք է, որը ունի իր սեփական տիպը։ +3. `typeof alert`-ի արդյունքը `"function"` է, քանի որ `alert`-ը ֆունկցիա է։ Մենք կուսումնասիրենք ֆունկցիաները հաջորդ գլուխներում, որտեղ կիմանանք, որ JavaScript-ը չունի առանձին function տիպ։ Ֆունկցիաները պատկանում են object տիպին։ Բայց `typeof`-ը մշակում է դրանք հատուկ ձևով՝ վերադարձնելով `"function"` արժեքը։ Դա նույնպես գալիս է JavaScript-ի պատմության վաղ ժամանակներից։ Տեխնիկապես վարքագիծը ճիշտ չէ, բայց պրակտիկայում կարող է հարմար լինել։ ```smart header="The `typeof(x)` syntax" You may also come across another syntax: `typeof(x)`. It's the same as `typeof x`. @@ -263,25 +275,26 @@ Usually, such parentheses contain a mathematical expression, such as `(2 + 2)`, Some people prefer `typeof(x)`, although the `typeof x` syntax is much more common. ``` -## Summary +## Ամփոփում -There are 8 basic data types in JavaScript. +JavaScript-ում գոյություն ունեն տվյալների 8 տիպեր։ -- Seven primitive data types: - - `number` for numbers of any kind: integer or floating-point, integers are limited by ±(253-1). - - `bigint` for integer numbers of arbitrary length. - - `string` for strings. A string may have zero or more characters, there's no separate single-character type. - - `boolean` for `true`/`false`. - - `null` for unknown values -- a standalone type that has a single value `null`. - - `undefined` for unassigned values -- a standalone type that has a single value `undefined`. - - `symbol` for unique identifiers. -- And one non-primitive data type: - - `object` for more complex data structures. +- Տվյալների յոթ պրիմիտիվ տիպեր՝ + - `number` բոլոր տեսակի թվերի համար․ ամբողջ և տասնորդական, ամբողջ թվերը սահմանափակված են ±(253-1) միջակայքում։ + - `bigint` կամայական մեծության ամբողջ թվերի համար։ + - `string` տողերի համար։ Տողը կարող է պարունակել զրո կամ ավել նիշեր, չկա նիշի համար նախատեսված առանձին տիպ։ + - `boolean` `true`/`false` արժեքների համար։ + - `null` անհայտ արժեքների համար․ առանձին տիպ է, որը ունի մեկ արժեք՝ `null`։ + - `undefined` չվերագրված արժեքների համար․ առանձին տիպ է, որը ունի մեկ արժեք՝ `undefined`։ + - `object` ավելի բարդ տվյալների կառուցվածքների համար։ + - `symbol` չկրկնվող նույնացուցիչների համար։ +- Եվ տվյալների ոչ պրիմիտիվ մեկ տիպ՝ + - `object` տվյալների բարդ կառուցվածքների համար։ -The `typeof` operator allows us to see which type is stored in a variable. +`typeof`-ը թույլ է տալիս ստուգել, թե ինչ տիպի արժեք է պահված փոփոխականում։ -- Usually used as `typeof x`, but `typeof(x)` is also possible. -- Returns a string with the name of the type, like `"string"`. -- For `null` returns `"object"` -- this is an error in the language, it's not actually an object. +- Ունի երկու ձև․ `typeof x` կամ `typeof(x)`։ +- Վերադարձնում է տող, որը պարունակում է տիպի անվանումը, օրինակ՝ `"string"`։ +- `null`-ի դեպքում վերադարձնում է `"object"`․ սա լեզվի սխալ է, այն իրականում օբյեկտ չէ։ -In the next chapters, we'll concentrate on primitive values and once we're familiar with them, we'll move on to objects. +Հաջորդ գլուխներում մենք կկենտրոնանանք պրիմիտիվ արժեքների վրա և երբ ծանոթանանք դրանց հետ, կանցնենք օբյեկտների ուսումնասիրությանը։ diff --git a/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/solution.md b/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/solution.md index 903ee7ff3..8f9b064c3 100644 --- a/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/solution.md +++ b/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/solution.md @@ -1,11 +1,11 @@ -JavaScript-code: +JavaScript կոդը․ ```js demo run -let name = prompt("What is your name?", ""); +let name = prompt("Ի՞նչ է Ձեր անունը։", ""); alert(name); ``` -The full page: +Ամբողջական էջը․ ```html @@ -15,7 +15,7 @@ The full page: diff --git a/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/task.md b/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/task.md index a65a654e0..e398ce6d0 100644 --- a/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/task.md +++ b/1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/task.md @@ -2,8 +2,8 @@ importance: 4 --- -# A simple page +# Պարզ էջ -Create a web-page that asks for a name and outputs it. +Կառուցե՛ք էջ, որը օգտատիրոջից կհարցնի իր անունը և կպատկերի այն։ [demo] diff --git a/1-js/02-first-steps/06-alert-prompt-confirm/article.md b/1-js/02-first-steps/06-alert-prompt-confirm/article.md index ef0f333cb..1ab9f8a1a 100644 --- a/1-js/02-first-steps/06-alert-prompt-confirm/article.md +++ b/1-js/02-first-steps/06-alert-prompt-confirm/article.md @@ -1,105 +1,105 @@ -# Interaction: alert, prompt, confirm +# Փոխազդեցություն: alert, prompt, confirm -As we'll be using the browser as our demo environment, let's see a couple of functions to interact with the user: `alert`, `prompt` and `confirm`. +Քանի որ մենք օգտագործելու ենք զննիչները որպես ներկայացման տիրույթ, եկեք ուսումնասիրենք մի քանի ֆունկցիաներ՝ նախատեսված օգտատիրոջ հետ փոխազդեցության համար․ `alert`, `prompt` և `confirm`։ ## alert -This one we've seen already. It shows a message and waits for the user to press "OK". +Այս ֆունկցիայի հետ մենք արդեն առնչվել ենք։ Այն ցույց է տալիս հաղորդագրություն և սպասում է օգտատիրոջ՝ «OK» կոճակը սեղմելուն։ -For example: +Օրինակ․ ```js run -alert("Hello"); +alert("Բարև"); ``` -The mini-window with the message is called a *modal window*. The word "modal" means that the visitor can't interact with the rest of the page, press other buttons, etc, until they have dealt with the window. In this case -- until they press "OK". +Հաղորդագրությունը պարունակող փոքր պատուհանը կոչվում է *մոդալ պատուհան* (modal window)։ «Մոդալը» նշանակում է, որ օգտատերը չի կարող փոխազդել էջի մնացած մասի հետ, սեղմել այլ կոճակներ և այլն, քանի դեռ նա փոխազդում է պատուհանի հետ։ Այս պարագայում՝ քանի դեռ չի սեղմել «OK» կոճակը։ ## prompt -The function `prompt` accepts two arguments: +`prompt` ֆունկցիան ընդունում է երկու արգումենտ․ ```js no-beautify result = prompt(title, [default]); ``` -It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel. +Այն կպատկերի տեքստային հաղորդագրություն պարունակող մոդալ պատուհան, տեքստի մուտքագրման դաշտ և OK/Cancel կոճակներ։ `title` -: The text to show the visitor. +։ Տեքստը, որը կպատկերվի պատուհանում։ `default` -: An optional second parameter, the initial value for the input field. +: Ոչ պարտադիր երկրորդ արգումենտ՝ մուտքագրման դաշտի նախնական արժեքի համար։ -```smart header="The square brackets in syntax `[...]`" -The square brackets around `default` in the syntax above denote that the parameter is optional, not required. +```smart header="Քառակուսի փակագծերը `[...]` շարահյուսությունում" +Վերոնշյալ շարահյուսությունում `default`-ը շրջապատող քառակուսի փակագծերը նշանակում են, որ պարամետրի առկայությունը պարտադիր չէ։ ``` -The visitor can type something in the prompt input field and press OK. Then we get that text in the `result`. Or they can cancel the input by pressing Cancel or hitting the `key:Esc` key, then we get `null` as the `result`. +Օգտատերը կարող է մուտքագրման դաշտում լրացնել ինչ-որ բան և սեղմել OK։ Մուտքագրված տեքստը կվերագրվի `result` փոփոխականին։ Օգտատերը նաև կարող է չեղարկել մուտքագրումը՝ սեղմելով Cancel կամ ստեղնաշարի `key:Esc` կոճակները։ Այդ դեպքում `result`-ին կվերագրվի `null` արժեքը։ -The call to `prompt` returns the text from the input field or `null` if the input was canceled. +`prompt`-ի կանչը վերադարձնում է մուտքագրման դաշտում նշված տեքստը կամ `null`, եթե մուտքագրումը չեղարկվել է։ -For instance: +Օրինակ․ ```js run -let age = prompt('How old are you?', 100); +let age = prompt('Քանի՞ տարեկան ես։', 100); -alert(`You are ${age} years old!`); // You are 100 years old! +alert(`Դու ${age} տարեկան ես։`); // Դու 100 տարեկան ես։ ``` -````warn header="In IE: always supply a `default`" -The second parameter is optional, but if we don't supply it, Internet Explorer will insert the text `"undefined"` into the prompt. +````warn header="IE-ի համար միշտ սահմանեք լռելյայն (`default`) արժեք" +Երկրորդ պարամետրը պարտադիր չէ, բայց, եթե չսահմանենք այն, Internet Explorer-ը կտեղադրի `"undefined"` տեքստը prompt-ի մուտքագրման դաշտում։ -Run this code in Internet Explorer to see: +Աշխատեցրեք կոդը Internet Explorer-ում՝ արդյունքը տեսնելու համար․ ```js run -let test = prompt("Test"); +let test = prompt("Թեստ"); ``` -So, for prompts to look good in IE, we recommend always providing the second argument: +Այսպիսով, որպեսզի prompt-ը ունենա նորմալ տեսք IE-ում, խորհուրդ է տրվում միշտ սահմանել երկրորդ արգումենտը․ ```js run -let test = prompt("Test", ''); // <-- for IE +let test = prompt("Թեստ", ''); // <-- IE-ի համար ``` ```` ## confirm -The syntax: +Շարահյուսությունը (syntax)․ ```js result = confirm(question); ``` -The function `confirm` shows a modal window with a `question` and two buttons: OK and Cancel. +`confirm` ֆունկցիան պատկերում է մոդալ պատուհան `question` հարցման տեքստով և երկու կոճակով՝ OK և Cancel։ -The result is `true` if OK is pressed and `false` otherwise. +Արդյունքը կլինի `true`, եթե սեղմվի OK կոճակը, և `false`՝ հակառակ դեպքում։ -For example: +Օրինակ․ ```js run -let isBoss = confirm("Are you the boss?"); +let isBoss = confirm("Դու՞ք եք այստեղ գլխավորը։"); -alert( isBoss ); // true if OK is pressed +alert( isBoss ); // true, եթե սեղմվի OK կոճակը ``` -## Summary +## Ամփոփում -We covered 3 browser-specific functions to interact with visitors: +Մենք ուսումնասիրեցինք 3 զննիչային (browser-specific) ֆունկցիաներ, որոնք փոխազդում են օգտատիրոջ հետ․ `alert` -: shows a message. +: պատկերում է հաղորդագրություն։ `prompt` -: shows a message asking the user to input text. It returns the text or, if Cancel button or `key:Esc` is clicked, `null`. +: պատկերում է հաղորդագրություն, սպասելով օգտատիրոջ կողմից տեքստի մուտքագրմանը։ Այն վերադարձնում է տեքստը, կամ, եթե սեղմվել է Cancel կամ `key:Esc` կոճակը, ապա վերադարձնում է `null`։ `confirm` -: shows a message and waits for the user to press "OK" or "Cancel". It returns `true` for OK and `false` for Cancel/`key:Esc`. +: պատկերում է հաղորդագրություն և սպասում է օգտատիրոջ «OK» կամ «Cancel» սեղմելուն։ OK-ի դեպքում վերադարձնում է `true`, իսկ Cancel/`key:Esc`-ի դեպքում՝ `false`։ -All these methods are modal: they pause script execution and don't allow the visitor to interact with the rest of the page until the window has been dismissed. +Այս բոլոր մեթոդները մոդալային են․ դրանք կանգնեցնում են սկրիպտի իրականցումը և թույլ չեն տալիս օգտատիրոջը փոխազդել էջի մնացած մասի հետ, քանի դեռ պատուհանը չի փակվել։ -There are two limitations shared by all the methods above: +Վերոնշյալ մեթոդները ունեն երկու սահմանափակում․ -1. The exact location of the modal window is determined by the browser. Usually, it's in the center. -2. The exact look of the window also depends on the browser. We can't modify it. +1. Մոդալ պատուհանի դիրքը որոշվում է զննիչի կողմից։ Սովորաբար այն լինում է կենտրոնում։ +2. Պատուհանի տեսքը նույնպես որոշվում է զննիչի կողմից։ Մենք չենք կարող այն փոփոխել։ -That is the price for simplicity. There are other ways to show nicer windows and richer interaction with the visitor, but if "bells and whistles" do not matter much, these methods work just fine. +Այսպիսին է պարզության գինը։ Կան շատ այլ եղանակներ՝ ավելի գեղեցիկ պատուհաններ պատկերելու և օգտատիրոջ հետ ավելի լայն փոխազդեցություն ապահովելու համար, բայց եթե «ճոխությունը» կարևոր չէ, այս մեթոդները հիանալի լուծում են։ diff --git a/1-js/02-first-steps/07-type-conversions/article.md b/1-js/02-first-steps/07-type-conversions/article.md index 329556141..501a9849f 100644 --- a/1-js/02-first-steps/07-type-conversions/article.md +++ b/1-js/02-first-steps/07-type-conversions/article.md @@ -1,150 +1,150 @@ -# Type Conversions +# Տիպերի փոխարկումներ (Type Conversions) -Most of the time, operators and functions automatically convert the values given to them to the right type. +Հաճախ օպերատորները և ֆունկցիաները ինքնաբերաբար փոխարկում են իրենց տրված արժեքները անհրաժեշտ տիպի։ -For example, `alert` automatically converts any value to a string to show it. Mathematical operations convert values to numbers. +Օրինակ՝ `alert`-ը ինքնաբերաբար փոխարկում է ցանկացած արժեք տողի (string)՝ այն պատկերելու համար։ Մաթեմատիկական գործողությունները փոխարկում են արժեքները թվերի։ -There are also cases when we need to explicitly convert a value to the expected type. +Նաև լինում են դեպքեր, երբ մենք կարիք ենք ունենում բացահայտորեն փոխարկել արժեքը անհրաժեշ տիպի։ -```smart header="Not talking about objects yet" -In this chapter, we won't cover objects. For now, we'll just be talking about primitives. +```smart header="Դեռևս չենք խոսում օբյեկտների մասին" +Այս գլխում մենք չենք լուսաբանի օբյեկտները։ Առայժմ կխոսենք միայն պրիմիտիվների մասին։ -Later, after we learn about objects, in the chapter we'll see how objects fit in. +Հետագայում, երբ կծանոթանանք օբյեկտների հետ գլխում, կտեսնենք, թե ինչպես են փոխարկվում օբյեկտները։ ``` -## String Conversion +## Տողային փոխարկում (String Conversion) -String conversion happens when we need the string form of a value. +Տողի փոխարկումը տեղի է ունենում, երբ կարիք է լինում ներկայացնել արժեքի տողային տեսքը։ -For example, `alert(value)` does it to show the value. +Օրինակ՝ `alert(value)`-ն կատարում է փոխարկում՝ արժեքը պատկերելու համար։ -We can also call the `String(value)` function to convert a value to a string: +Մենք կարող ենք կանչել `String(value)` ֆունկցիան՝ արժեքը տողի փոխարկելու համար․ ```js run let value = true; alert(typeof value); // boolean *!* -value = String(value); // now value is a string "true" +value = String(value); // այստեղ value-ին վերագրվեց "true" տողը alert(typeof value); // string */!* ``` -String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc. +Տողի փոխարկման արդյունքը հիմնականում ակնհայտ է։ `false`-ը դառնում է `"false"`, `null`-ը դառնում է `"null"` և այլն։ -## Numeric Conversion +## Թվային փոխարկում (Numeric Conversion) -Numeric conversion in mathematical functions and expressions happens automatically. +Մաթեմատիկական ֆունկցիաներում և արտահայտություններում այլ արժեքներիից թվին փոխարկումը տեղի է ունենում ավտոմատ։ -For example, when division `/` is applied to non-numbers: +Օրինակ՝ երբ բաժանումը `/` կիրառվում է ոչ թվային արժեքների վրա․ ```js run -alert( "6" / "2" ); // 3, strings are converted to numbers +alert( "6" / "2" ); // 3, տողերը փոխարկվում են թվերի ``` -We can use the `Number(value)` function to explicitly convert a `value` to a number: +Մենք կարող ենք կիրառել `Number(value)` ֆունկցիան՝ `value`-ն բացահայտ կերպով թվի փոխարկելու համար․ ```js run let str = "123"; alert(typeof str); // string -let num = Number(str); // becomes a number 123 +let num = Number(str); // դառնում է թիվ 123 alert(typeof num); // number ``` -Explicit conversion is usually required when we read a value from a string-based source like a text form but expect a number to be entered. +Բացահայտ փոխարկումը հաճախ նախընտրելի է, երբ որևէ թվի մուտքագրում ակնկալող տեքստային դաշտից արժեք վերցնելու կարիք կա։ -If the string is not a valid number, the result of such a conversion is `NaN`. For instance: +Երբ տողից թվի փոխարկումը վավեր չէ, այդ փոխարկման արդյունքը կլինի `NaN`։ Օրինակ․ ```js run -let age = Number("an arbitrary string instead of a number"); +let age = Number("կամայական տող, թվի փոխարեն"); -alert(age); // NaN, conversion failed +alert(age); // NaN, փոխարկումը ձախողվել է ``` -Numeric conversion rules: +Թվային փոխարկումների կանոնները․ -| Value | Becomes... | +| Արժեքը | Փոխարկվում է... | |-------|-------------| |`undefined`|`NaN`| |`null`|`0`| -|true and false | `1` and `0` | -| `string` | Whitespaces (includes spaces, tabs `\t`, newlines `\n` etc.) from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`. | +|true և false | `1` և `0` | +| `string` | Սկզբում և վերջում եղած բացատները (ներառյալ space-ներ, թաբեր `\t`, նոր տողեր `\n`, և այլն) հեռացվում են։ Եթե ստացված տողը դատարկ է, արդյունքը դառնում է `0`։ Հակառակ դեպքում, ոչ դատարկ տողից «կարդացվում է» թիվը։ Ձախողման դեպքում արդյունքը դառնում է `NaN`։ | -Examples: +Օրինակներ․ ```js run alert( Number(" 123 ") ); // 123 -alert( Number("123z") ); // NaN (error reading a number at "z") +alert( Number("123z") ); // NaN (փոխարկումը ձախողվել է "z"-ի առկայության պատճառով) alert( Number(true) ); // 1 alert( Number(false) ); // 0 ``` -Please note that `null` and `undefined` behave differently here: `null` becomes zero while `undefined` becomes `NaN`. +Նշենք, որ `null`-ը և `undefined`-ը իրենց տարբեր կերպ են դրսևորում՝ `null`-ը դառնում է զրո, մինչդեռ `undefined`-ը դառնում է `NaN`։ -Most mathematical operators also perform such conversion, we'll see that in the next chapter. +Մաթեմատիկական օպերատորների գերակշիռ մասը նույնպես իրականացնում է նման փոխարկում։ Մենք կուսումնասիրենք դրանք հաջորդ գլխում։ -## Boolean Conversion +## Տրամաբանական փոխարկում (Boolean Conversion) -Boolean conversion is the simplest one. +Տրամաբանական փոխարկումը ամենապարզն է։ -It happens in logical operations (later we'll meet condition tests and other similar things) but can also be performed explicitly with a call to `Boolean(value)`. +Այն տեղի է ունենում տրամաբանական գործողություններում (ավելի ուշ կծանոթանանք պայմանական ստուգումների և նման այլ կառուցվածքների հետ), բայց նաև կարող է իրականացվել բացահայտ կերպով՝ `Boolean(value)` ֆունկցիայի միջոցով։ -The conversion rule: +Փոխարկման կանոնները․ -- Values that are intuitively "empty", like `0`, an empty string, `null`, `undefined`, and `NaN`, become `false`. -- Other values become `true`. +- Արժեքները, որոնք ենթադրում են «դատարկություն», ինչպես `0`-ն, դատարկ տողը, `null`-ը, `undefined`-ը և `NaN`-ը, դառնում են `false`։ +- Մնացած արժեքները դառնում են `true`։ -For instance: +Օրինակ՝ ```js run alert( Boolean(1) ); // true alert( Boolean(0) ); // false -alert( Boolean("hello") ); // true +alert( Boolean("բարև") ); // true alert( Boolean("") ); // false ``` -````warn header="Please note: the string with zero `\"0\"` is `true`" -Some languages (namely PHP) treat `"0"` as `false`. But in JavaScript, a non-empty string is always `true`. +````warn header="Հիշե՛ք, զրո պարունակող տողը `\"0\"` `true` է" +Որոշ լեզուներ (օրինակ՝ PHP-ն) ընկալում են `"0"` տողը որպես `false`։ Բայց JavaScript-ում ոչ դատարկ տողը միշտ `true` է։ ```js run alert( Boolean("0") ); // true -alert( Boolean(" ") ); // spaces, also true (any non-empty string is true) +alert( Boolean(" ") ); // բացատը նույնպես true է (ցանկացած ոչ դատարկ տող true է) ``` ```` -## Summary +## Ամփոփում -The three most widely used type conversions are to string, to number, and to boolean. +Առավել հաճախ կիրառվող տիպային փոխարկումները տողային, թվային և տրամաբանական փոխարկումներն են։ -**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values. +**`Տողային փոխարկում`** -- Տեղի է ունենում ինչ-որ բանի պատկերման դեպքում։ Կարող է իրականացվել `String(value)`-ի միջոցով։ Տողային փոխարկումը պրիմիտիվ արժեքների դեպքում կանխատեսելի է։ -**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`. +**`Թվային փոխարկում`** -- Տեղի է ունենում մաթեմատիկական գործողություններում։ Կարող է իրականացվել `Number(value)`-ի միջոցով։ -The conversion follows the rules: +Փոխարկումը ենթարկվում է հետևյալ կանոններին․ -| Value | Becomes... | +| Արժեքը | Փոխարկվում է... | |-------|-------------| |`undefined`|`NaN`| |`null`|`0`| |true / false | `1 / 0` | -| `string` | The string is read "as is", whitespaces (includes spaces, tabs `\t`, newlines `\n` etc.) from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. | +| `string` | Տողերը կարդացվում են ինչպես կան, եզրերում եղած բացատները (ներառյալ space-ներ, թաբեր `\t`, նոր տողեր `\n`, և այլն) անտեսվում են։ Դատարկ տողը դառնում է `0`։ Ձախողման դեպքում ստացվում է `NaN`։ | -**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`. +**`Տրամաբանական փոխարկում`** -- Տեղի է ունենում տրամաբանական գործողություններում։ Կարող է իրականացվել `Boolean(value)`-ի միջոցով։ -Follows the rules: +Ենթարկվում է հետևյալ կանոններին․ -| Value | Becomes... | +| Արժեքը | Փոխարկվում է... | |-------|-------------| |`0`, `null`, `undefined`, `NaN`, `""` |`false`| -|any other value| `true` | +|ցանկացած այլ արժեք| `true` | -Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are: +Այս կանոնների մեծ մասը հեշտ է հասկանալ և հիշել։ Բացառություն են կազմում հետևյալ դեպքերը, որտեղ մարդիկ հաճախակի են սխալվում․ -- `undefined` is `NaN` as a number, not `0`. -- `"0"` and space-only strings like `" "` are true as a boolean. +- `undefined`-ը որպես թիվ `NaN` է, ոչ թե `0`։ +- `"0"`-ն և միայն բացատներից կազմված տողը՝ ինչպես `" "`, true են։ -Objects aren't covered here. We'll return to them later in the chapter that is devoted exclusively to objects after we learn more basic things about JavaScript. +Այս գլխում չխոսվեց օբյեկտների մասին։ Մենք կվերադառնանք դրանց ավելի ուշ՝ ամբողջությամբ օբյեկտներին նվիրված գլխում, JavaScript-ի տարրական գաղափարները ավելի հիմնովին ուսումնասիրելուց հետո։ diff --git a/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md b/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md index 209a0702c..cf9c62b9f 100644 --- a/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md +++ b/1-js/02-first-steps/08-operators/4-fix-prompt/solution.md @@ -1,6 +1,6 @@ -The reason is that prompt returns user input as a string. +Պատճառը այն է որ մուտքագրված թվերը վերդարձվում են որպես տող։ -So variables have values `"1"` and `"2"` respectively. +Այսպիսով փոփոխականները ունեն `"1"` և `"2"` արժեքները։ ```js run let a = "1"; // prompt("First number?", 1); @@ -9,9 +9,9 @@ let b = "2"; // prompt("Second number?", 2); alert(a + b); // 12 ``` -What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`. +Այն, ինչ մենք պետք է անենք, տողերը թվեր փոխարկելն է `+`-ից առաջ։ Օրինակ՝ կիրառելով `Number()` կամ դնելով դիմացից `+`։ -For example, right before `prompt`: +Օրինակ՝ `prompt`-ից անմիջապես առաջ: ```js run let a = +prompt("First number?", 1); @@ -20,7 +20,7 @@ let b = +prompt("Second number?", 2); alert(a + b); // 3 ``` -Or in the `alert`: +Կամ `alert`-ի մեջ: ```js run let a = prompt("First number?", 1); @@ -29,4 +29,4 @@ let b = prompt("Second number?", 2); alert(+a + +b); // 3 ``` -Using both unary and binary `+` in the latest code. Looks funny, doesn't it? +Կիրառվել են և ունար և բինար `+`վերջին կոդւոմ։ Հիանալի տեսք ունի, այդպես չէ՞ diff --git a/1-js/02-first-steps/08-operators/4-fix-prompt/task.md b/1-js/02-first-steps/08-operators/4-fix-prompt/task.md index b3ea4a3a3..d15855531 100644 --- a/1-js/02-first-steps/08-operators/4-fix-prompt/task.md +++ b/1-js/02-first-steps/08-operators/4-fix-prompt/task.md @@ -2,13 +2,13 @@ importance: 5 --- -# Fix the addition +# Ուղղել գումարումը -Here's a code that asks the user for two numbers and shows their sum. +Գրված է կոդի հատված, որը օգտագործողից ստանում է երկու թվեր և ցուցադրում է դրանց գումարը։ -It works incorrectly. The output in the example below is `12` (for default prompt values). +Սա աշխատում է սխալ։ Ելքային արդյունքը, պատկերված օրինակում `12`-է (լռելայն արժեքների դեպքում)։ -Why? Fix it. The result should be `3`. +Ինչու՞ ուղղել դա։ Արդյունքը պետք է լինի `3`. ```js run let a = prompt("First number?", 1); diff --git a/1-js/02-first-steps/08-operators/article.md b/1-js/02-first-steps/08-operators/article.md index d52c37a17..1bfccc7df 100644 --- a/1-js/02-first-steps/08-operators/article.md +++ b/1-js/02-first-steps/08-operators/article.md @@ -1,15 +1,15 @@ -# Basic operators, maths +# Մաթեմատիկական տարրական գործողություններ -We know many operators from school. They are things like addition `+`, multiplication `*`, subtraction `-`, and so on. +Մենք գպրոցից գիտեն շատ գործողություններ։ Դրանցից են, օրինակ գումարում `+`, բազմապատկում `*`, հանում `-` և այլն։ -In this chapter, we’ll start with simple operators, then concentrate on JavaScript-specific aspects, not covered by school arithmetic. +Այս հատվածում, մենք կսկսենք պարզ գործողույթուններից, ապա կկենտրոնանանք JavaScript-ի հատուկ ասպեկտների վրա, որոնք գոյություն չունեն դպրոցական թվաբանության մեջ։ -## Terms: "unary", "binary", "operand" +## "ունար", "բինար" և "օպերանդ" հասկացությունները -Before we move on, let's grasp some common terminology. +Մինչ առաջ անցնելը, եկեք հասկանանք որոշ տերմինների նշանակությունը։ -- *An operand* -- is what operators are applied to. For instance, in the multiplication of `5 * 2` there are two operands: the left operand is `5` and the right operand is `2`. Sometimes, people call these "arguments" instead of "operands". -- An operator is *unary* if it has a single operand. For example, the unary negation `-` reverses the sign of a number: +- *Նշան* -- հասկացություն, որը կազմում է գործողությունների հիմքը։ Օրինակ ՝ `5 * 2` –ի բազմապատկման մեջ կան երկու օպերանդներ՝ ձախ օպերանդը՝ `5`, իսկ աջը՝ `2`: Երբեմն, մարդիկ «օպերանդներ»-ի փոխարեն, անվանում են «արգումենտներ»: +- Գործողությունը համարվում է *ունար* եթե այն ունի միայն մեկ օպերանդ։ Օրինակ՝ ունար ժխտումը `-` հակադարձում է թվի նշանը: ```js run let x = 1; @@ -17,51 +17,51 @@ Before we move on, let's grasp some common terminology. *!* x = -x; */!* - alert( x ); // -1, unary negation was applied + alert( x ); // -1, կիրառվել է ունար ժխտում ``` -- An operator is *binary* if it has two operands. The same minus exists in binary form as well: +- Գործողույթունը համարվում է *երկուական* եթե այն ունի երկու օպերանդ. Նույն մինուսը գոյություն ունի նաև հանման տեսքով: ```js run no-beautify let x = 1, y = 3; - alert( y - x ); // 2, binary minus subtracts values + alert( y - x ); // 2, երկուական մինուսը ցույց է տալիս արժեքների տարբերությունը ``` - Formally, in the examples above we have two different operators that share the same symbol: the negation operator, a unary operator that reverses the sign, and the subtraction operator, a binary operator that subtracts one number from another. + Վերը նշված օրինակներում մենք ունենք երկու տարբեր օպերատորներ, որոնք կիրառում են նույն նշանը. Ժխտման օպերատոր, նշանը հակադարձող ունարի օպերատոր և հանում օպերատոր, երկուական օպերատոր, որը հանում է մեկ թիվը մյուսից: -## Maths +## Մաթեմատիկա -The following math operations are supported: +Հետևյալ մաթեմատիկական գործողությունները աջակցվում են․ -- Addition `+`, -- Subtraction `-`, -- Multiplication `*`, -- Division `/`, -- Remainder `%`, -- Exponentiation `**`. +- Գումարում `+`, +- Հանում `-`, +- Բազմապատկում `*`, +- Բաժանում `/`, +- Մնացորդ `%`, +- Աստիճան բարձրացնել (անգլ․՝ Exponentiation) `**`. -The first four are straightforward, while `%` and `**` need a few words about them. +Առաջին չորս գործողությունները պարզ են, մինչդեռ `%` և `**` գործողությունների համար, մի քան խոսք ավելին։ -### Remainder % +### Մնացորդ % -The remainder operator `%`, despite its appearance, is not related to percents. +Մնացորդի օպերատորը հետևյալն է `%`, չնայած նշանի պատկերմանը, դա կապված չէ տոկոսների հետ: -The result of `a % b` is the [remainder](https://en.wikipedia.org/wiki/Remainder) of the integer division of `a` by `b`. +Հետրյալ հավասարման `a % b` արդյունքը [remainder](https://en.wikipedia.org/wiki/Remainder) `a` բաժանած `b` մնացորդն է։ -For instance: +Օրինակ՝ ```js run -alert( 5 % 2 ); // 1, the remainder of 5 divided by 2 -alert( 8 % 3 ); // 2, the remainder of 8 divided by 3 -alert( 8 % 4 ); // 0, the remainder of 8 divided by 4 +alert( 5 % 2 ); // 1, 5-ը բաժանած 2-ի մնացորդը +alert( 8 % 3 ); // 2, 8-ը բաժանած 3-ի մնացորդը +alert( 8 % 4 ); // 0, 8-ը բաժանած 4-ի մնացորդը ``` -### Exponentiation ** +### Աստիճան բարձրացնել ** -The exponentiation operator `a ** b` raises `a` to the power of `b`. +Աստիճան բարձրացնելու օպերատորը `a ** b` բարձրացնում է `a`-ն `b`-ի աստիճան. -In school maths, we write that as ab. +Դպրոցական մաթեմատիկայում այն գրում ենք հետևյալ տեսքով ab։ -For instance: +Օրինակ՝ ```js run alert( 2 ** 2 ); // 2² = 4 @@ -69,9 +69,9 @@ alert( 2 ** 3 ); // 2³ = 8 alert( 2 ** 4 ); // 2⁴ = 16 ``` -Just like in maths, the exponentiation operator is defined for non-integer numbers as well. +Ինչպես մաթեմատիկայում, այստեղ նույնպես աստիճան բարձրացնելու օպերատորը հասանելի է ոչ ամբողջ թվերի դեպքում ևս։ -For example, a square root is an exponentiation by ½: +Օրինակ՝ ½-ի աստիճանը: ```js run alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root) @@ -79,62 +79,62 @@ alert( 8 ** (1/3) ); // 2 (power of 1/3 is the same as a cubic root) ``` -## String concatenation with binary + +## Տողերի միավորումը երկուական +-ով -Let's meet the features of JavaScript operators that are beyond school arithmetics. +Եկեք ծանոթանանք JavaScript-ի այլ հնարավորությունների հետ։ -Usually, the plus operator `+` sums numbers. +Սովորաբար, `+` գործողությունը գումարում է թվերը։ -But, if the binary `+` is applied to strings, it merges (concatenates) them: +Բայց, երբ երկուական `+`-ը կիրառովում է տողերի համար, դա միացնում է դրանք․ ```js let s = "my" + "string"; alert(s); // mystring ``` -Note that if any of the operands is a string, then the other one is converted to a string too. +Նշում, եթե ցանկացած օպրանդ տող է, ապա մյուս օպերանդը նույնպես ձևափոխվում է տողի։ -For example: +Օրինակ՝ ```js run alert( '1' + 2 ); // "12" alert( 2 + '1' ); // "21" ``` -See, it doesn't matter whether the first operand is a string or the second one. +Կապ չունի այն, որ առաջին օպերանդն է տող, թե երկրորդը․ -Here's a more complex example: +Դիտարկենք ավելի բարդ օրինակ՝ ```js run -alert(2 + 2 + '1' ); // "41" and not "221" +alert(2 + 2 + '1' ); // "41", այլ ոչ թե "221" ``` -Here, operators work one after another. The first `+` sums two numbers, so it returns `4`, then the next `+` adds the string `1` to it, so it's like `4 + '1' = '41'`. +Այստեղ օպերատորները աշխատում են հաջորդաբար։ Առաջին `+`-ը գումարում է երկու թվերը, վարադարձնում է `4`, ապա հաջորդ `+`-ը ավալցանում`1` տողային փոփոխականը, այսպիսով դա նման է հետևյալին `4 + '1' = '41'`. ```js run -alert('1' + 2 + 2); // "122" and not "14" +alert('1' + 2 + 2); // "122", այլ ոչ թե "14" ``` -Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`. +Այստեղ առաջին օպերանդը տող է, կոմպիլյատորը վերաբերվում է մյուս օպերանդներին նույնպես տող . `2`-ը կմիավորվի `'1'`-ի հետ, այսպիսով դա նման է հետևյալին `'1' + 2 = "12"` և `"12" + 2 = "122"`. -The binary `+` is the only operator that supports strings in such a way. Other arithmetic operators work only with numbers and always convert their operands to numbers. +Երկուական `+`-ը միակ օպերատորնե, որը նման կերպ է վարվում տողերի հետ։ Մյուս թվաբանական օպերատորները աշխատում են միայն թվերի հետ և միշտ կերպափոխում են օպերանդները թվերի։ -Here's the demo for subtraction and division: +Դիտարկենք հանման և բաժանման ցուցադրությունը․ ```js run -alert( 6 - '2' ); // 4, converts '2' to a number -alert( '6' / '2' ); // 3, converts both operands to numbers +alert( 6 - '2' ); // 4, '2'-ը ձևափոխվում է թվի +alert( '6' / '2' ); // 3, երկու օպերանդներնել ձևափոխվում են թվերի ``` -## Numeric conversion, unary + +## Թվային կերպափոխումներ, ունար + -The plus `+` exists in two forms: the binary form that we used above and the unary form. +Գոյություն ունի `+`-ի երկու տեսակ․ երկուական տեսակ, որը մենք կիրառեցինք վերևում և ունար տեսակ։ -The unary plus or, in other words, the plus operator `+` applied to a single value, doesn't do anything to numbers. But if the operand is not a number, the unary plus converts it into a number. +Ունար գումարում կամ մեկ այլ խոսքով `+` որը կիրառվում է մեկ արժեքների դեպքում, թվերի վրա չի ազդում։ Բայց եթե օպերանդը թիվ չէ, ապա ունար գումարումը այն կերպափոխում է թվի։ -For example: +Օրինակ՝ ```js run -// No effect on numbers +// Թվերի վրա ազդեցություն չի ունենում let x = 1; alert( +x ); // 1 @@ -142,77 +142,77 @@ let y = -2; alert( +y ); // -2 *!* -// Converts non-numbers +// Կերպափոխում է ոչ թվային արժեքները alert( +true ); // 1 alert( +"" ); // 0 */!* ``` -It actually does the same thing as `Number(...)`, but is shorter. +Այն իրականում անում է նույնը, ինչ `Number(...)`-ը, բայց կարճ տարբերակով։ -The need to convert strings to numbers arises very often. For example, if we are getting values from HTML form fields, they are usually strings. What if we want to sum them? +Տողերը թվերի կերպափոխելու անհրաժեշտությունը շատ հաճախ է առաջանում։ Օրինակ՝ եթե մենք ստանում ենք դաշտերը HTML ֆորմայից, դրանք սովորաբար տողային տիպի են։ Ի՞նչ կլինի այդ դեպքում դրանց գումարը։ -The binary plus would add them as strings: +Երկուական գումարումը դրանք կավելացնի իրար ինչպես տող։ ```js run let apples = "2"; let oranges = "3"; -alert( apples + oranges ); // "23", the binary plus concatenates strings +alert( apples + oranges ); // "23", երկուական գումարը միացնում է տողերը իրար հետ ``` -If we want to treat them as numbers, we need to convert and then sum them: +Եթե մենք ուզում ենք նրանց վերաբերվել որպես թվերի, կարիք կա կերպափոխելու դրանք և կատարել դրանց գումարումը: ```js run let apples = "2"; let oranges = "3"; *!* -// both values converted to numbers before the binary plus +// երկու արժեքները մինչև երկուական գումարմանը մասնակցելը, կերպափոխվում են թվերի alert( +apples + +oranges ); // 5 */!* -// the longer variant +// երկար տարբերակը // alert( Number(apples) + Number(oranges) ); // 5 ``` -From a mathematician's standpoint, the abundance of pluses may seem strange. But from a programmer's standpoint, there's nothing special: unary pluses are applied first, they convert strings to numbers, and then the binary plus sums them up. +Մաթեմատիկական տեսանկյունից, պլյուսների առատությունը կարող է տարօրինակ թվալ։ Բայց ծրագրավորողների տեսանկյունից, հատուկ ոչինչ չկա: ունար պլյուսը կիրառվում է սկզբից, դրանք կերպափոխում են տողերը թվերի, իսկ երկուական պլյուսը գումարում է դրանք։ -Why are unary pluses applied to values before the binary ones? As we're going to see, that's because of their *higher precedence*. +Ինչու՞ է ունար պլյուսը կիրառվում սկզբից, նախքան երկուականը, դա կախված է *բարձր առաջնահերթություն*. -## Operator precedence +## Օպերատորների առաջնահերթություն -If an expression has more than one operator, the execution order is defined by their *precedence*, or, in other words, the default priority order of operators. +Եթե արդահայտությունը ունի մեկից ավել օպերատորներ, ապա կատարման հերթականությունը սահմանվում է կախված նրանց *առաջնահերթությունից*, կամ այլ բառով, օպերատորների կանխադրված առաջնահերթ կարգը։ -From school, we all know that the multiplication in the expression `1 + 2 * 2` should be calculated before the addition. That's exactly the precedence thing. The multiplication is said to have *a higher precedence* than the addition. +Դպրոցից մենք գիտեն արտահայտությունում բազմապատկման կարգի մասին `1 + 2 * 2` պետք է կատարվի մինչ գումարումը։ Դա հենց առաջնահերթությունն է: Ասում են, որ բազմապատկումը ունի *ավելի բարձր առաջնահերթություն* քան թե գումարումը։ -Parentheses override any precedence, so if we're not satisfied with the default order, we can use them to change it. For example, write `(1 + 2) * 2`. +Փակագծերը ավելի առաջնահերթ են քան մյուսները, ուստի, եթե մենք համամիտ չենք առաջնահերթությունից, կարող ենք օգտագործել դրանք, այն փոխելու համար: Օրինակ՝ գրելով `(1 + 2) * 2`. -There are many operators in JavaScript. Every operator has a corresponding precedence number. The one with the larger number executes first. If the precedence is the same, the execution order is from left to right. +Կան բազմաթիվ օպերատորներ JavaScript-ում։ Յուրաքանչյուր օպերատոր ունի իր համապատասխան առաջնահերթության համարը: Ավելի մեծ թիվ ունեցողը կատարվում է առաջինը։ Եթե առաջնահերթությունը նույնն է, ապա կատարման հերթականությունը ձախից դեպի աջ է։ -Here's an extract from the [precedence table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) (you don't need to remember this, but note that unary operators are higher than corresponding binary ones): +Ահա քաղվածքը [precedence table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) (դուք պարտավոր չեք հիշել սա, բայց նշեք, որ ունար օպերատորներն ավելի բարձր են, քան համապատասխան երկուականները): -| Precedence | Name | Sign | +| Առաջնահերթություն | Անվանում | Նշան | |------------|------|------| | ... | ... | ... | -| 14 | unary plus | `+` | -| 14 | unary negation | `-` | -| 13 | exponentiation | `**` | -| 12 | multiplication | `*` | -| 12 | division | `/` | -| 11 | addition | `+` | -| 11 | subtraction | `-` | +| 14 | ունար պլյուս | `+` | +| 14 | ունար ժխտում | `-` | +| 13 | աստիճան բարձրացում | `**` | +| 12 | բազմապատկում | `*` | +| 12 | բաժանում | `/` | +| 11 | գումարում | `+` | +| 11 | հանում | `-` | | ... | ... | ... | -| 2 | assignment | `=` | +| 2 | վերագրում | `=` | | ... | ... | ... | -As we can see, the "unary plus" has a priority of `14` which is higher than the `11` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition. +Կարող ենք տեսնել, "ունար պլյուս"-ը ունի `14` գերակայությունը, որը մեծ է քան `11`-ը "գումարում" (երկուական պլյուս)։ Ահա թե ինչու է `"+apples + +oranges"` արտահայտությունում ունար պլյուսը կատարվում նախքան գումարումը։ -## Assignment +## Վերագրում -Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `2`. +Պետք է նշել այն, որ վերագրումը `=` նույնպես օպերատոոր է։ Այն գերակայության աղյուսակում ունի շատ ցածր դիրք՝ `2`։ -That's why, when we assign a variable, like `x = 2 * 2 + 1`, the calculations are done first and then the `=` is evaluated, storing the result in `x`. +Ահա ինչու, երբ մենք վերագրում ենք փոփոխկան, ինչպիսին է `x = 2 * 2 + 1`, հաշվարկը կատարվում է սկզբում և հետո կատարվում է`=`, պահպանելով արդյունքը `x`-ում։ ```js let x = 2 * 2 + 1; @@ -220,15 +220,15 @@ let x = 2 * 2 + 1; alert( x ); // 5 ``` -### Assignment = returns a value +### Վերագրումը = վերադարձնում է արժեք -The fact of `=` being an operator, not a "magical" language construct has an interesting implication. +Վերագրման `=` օպերատոր լինլու փաստը, ունի ոչ "կախարդական" ենթատեքստ։ -All operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`. +JavaScript-ում բոլոր օպերատորները վերադարձնում են արժեք։ Դա ակնհայտ է `+`-ի և `-`-ի համար, բայց նաև `=`-ի համար։ -The call `x = value` writes the `value` into `x` *and then returns it*. +`x = value`-ի կանչը գրանցում է `value`-ն `x`-ի մեջ *և վերադարձնում է այն*։ -Here's a demo that uses an assignment as part of a more complex expression: +Այա վերագրման կիրառման օրինակ, որպես բարդ արտահայտության հատված: ```js run let a = 1; @@ -242,15 +242,15 @@ alert( a ); // 3 alert( c ); // 0 ``` -In the example above, the result of expression `(a = b + 1)` is the value which was assigned to `a` (that is `3`). It is then used for further evaluations. +Վերը նշված օրինակում, հետևյալ արտահայտության `(a = b + 1)` արժեքը դա այն է, որը պետք է վերագրվի `a`-ին (դա `3`-ն է)։ Այնուհետեւ այն օգտագործվում է հետագա արժեվորման համար։ -Funny code, isn't it? We should understand how it works, because sometimes we see it in JavaScript libraries. +Զվարճալի կոդ է, այնպես չէ՞: Մենք պետք է հասկանանք թե ինչպես է այն աշխատում, քանի որ երբեմն այն կարող եք հանդիպել JavaScript-ի գրադարաններում։ -Although, please don't write the code like that. Such tricks definitely don't make code clearer or readable. +Ամեն դեպքում, խնդրում եմ, կոդը այդպես մի գրեք: Նման հնարքները հաստատ հստակ ու հասկանալի չեն դարձնում կոդը: -### Chaining assignments +### Կապակցված վերագրումներ -Another interesting feature is the ability to chain assignments: +Մեկ այլ հետաքրքիր առանձնահատկություն է վերգրումների կապակցումը․ ```js run let a, b, c; @@ -264,22 +264,22 @@ alert( b ); // 4 alert( c ); // 4 ``` -Chained assignments evaluate from right to left. First, the rightmost expression `2 + 2` is evaluated and then assigned to the variables on the left: `c`, `b` and `a`. At the end, all the variables share a single value. +Կապակցումը կատարվում է աջից դեպի ձախ։ Առաջին կատարվում է ամենաաջակողմյան `2 + 2` արդահայտությունը, ապա վերագրվում է ձախ կողմի փոփոխականին․ `c`, `b` և `a`։ Ամենավերջում, բոլոր փոփոխականները հավաքվում է մեկ արժեքի մեջ։ -Once again, for the purposes of readability it's better to split such code into few lines: +Կրկին անգամ, ընթերցելիության նկատառումներից ելնելով, լավ է որ այն բաժանված է մի քանի տողերի․ ```js c = 2 + 2; b = c; a = c; ``` -That's easier to read, especially when eye-scanning the code fast. +Սա հեշտ է ընթերցվում, հատկապես այն դեպքւոմ, երբ աչքը արագ է դիտարկում կոդը։ -## Modify-in-place +## Փոփոխել տեղում -We often need to apply an operator to a variable and store the new result in that same variable. +Երբեմն մենք կարիք ենք ունենում, կիրառել օպերատորը և պահպանել նոր արդյունքը նույն փոփոխականի մեջ։ -For example: +Օրինակ՝ ```js let n = 2; @@ -287,19 +287,19 @@ n = n + 5; n = n * 2; ``` -This notation can be shortened using the operators `+=` and `*=`: +Այս ամենը կարող ենք կարճ գրել `+=` և `*=`: ```js run let n = 2; -n += 5; // now n = 7 (same as n = n + 5) -n *= 2; // now n = 14 (same as n = n * 2) +n += 5; // այժմ n = 7 (նույնն է ինչ n = n + 5) +n *= 2; // այժմ n = 14 (նույնն է ինչ n = n * 2) alert( n ); // 14 ``` -Short "modify-and-assign" operators exist for all arithmetical and bitwise operators: `/=`, `-=`, etc. +Կարճ "ձևափոխել և վերագրել" օպերատորները գոյություն ունեն բոլոր մաթեմատիկական և բիթային օպերատորների համար․ `/=`, `-=` և այլն։ -Such operators have the same precedence as a normal assignment, so they run after most other calculations: +Նման օպերատորներն ունեն նույն գերակայությունը, ինչ սովորական վերագրումները, այնպես որ նրանք աշխատում են շատ այլ հաշվարկներից հետո. ```js run let n = 2; @@ -309,45 +309,45 @@ n *= 3 + 5; // right part evaluated first, same as n *= 8 alert( n ); // 16 ``` -## Increment/decrement +## Ինկրեմենտ/դեկրեմենտ -Increasing or decreasing a number by one is among the most common numerical operations. +Թիվը մեկով մեծացնելը կամ փոքրացնելը ամենատարածված թվային գործողություններից է։ -So, there are special operators for it: +Այսպիսով դրա համար կան հատուկ օպերատորներ․ -- **Increment** `++` increases a variable by 1: +- **Ինկրեմենտ** `++` փոփոխականի ավելացումը 1-ով․ ```js run no-beautify let counter = 2; - counter++; // works the same as counter = counter + 1, but is shorter + counter++; // կաշխատի որպես counter = counter + 1, բայց կարճ տարբերակով alert( counter ); // 3 ``` -- **Decrement** `--` decreases a variable by 1: +- **Դեկրեմենտ** `--` փոքրացնել փոփոխականը 1-ով․ ```js run no-beautify let counter = 2; - counter--; // works the same as counter = counter - 1, but is shorter + counter--; // կաշխատի որպես counter = counter - 1, բայց կարճ տարբերակով alert( counter ); // 1 ``` ```warn -Increment/decrement can only be applied to variables. Trying to use it on a value like `5++` will give an error. +Ինկրեմենտ/դեկրեմենտ պետք է կրատվի փոփոխականների համար։ Այն փորձելով օգտագործել օրինակ՝ `5++` փոփոխականի համար կստանանք սխալ։ ``` -The operators `++` and `--` can be placed either before or after a variable. +`++` և `--` օպերատորները կարող են տեղադրվել փոփոխականից առաջ և հետո։ -- When the operator goes after the variable, it is in "postfix form": `counter++`. -- The "prefix form" is when the operator goes before the variable: `++counter`. +- Երբ օպերատորը կիրառվում է փոփոխականից հետո, դա համարվում է "պոստֆիքս կառուցվածք"․ `counter++`. +- "պրեֆիքս կառուցվածք"-ը երբ կիրառվում է փոփոխականից առաջ․ `++counter`. -Both of these statements do the same thing: increase `counter` by `1`. +Բոլոր գործեղությունները կատարում են նույնը․ ավելացնում են `counter`-ին `1`. -Is there any difference? Yes, but we can only see it if we use the returned value of `++/--`. +Կա՞ արդյոք տարբերություն․ Այո, բայց դա մենք կարող ենք տեսնել դա միայն վերադարձվող արժեքում `++/--`. -Let's clarify. As we know, all operators return a value. Increment/decrement is no exception. The prefix form returns the new value while the postfix form returns the old value (prior to increment/decrement). +Եկեք պարզաբանենք։ Ինչպես գիտենք բոլոր օպերատորները վերադարձնում են արժեք։ Ինկրեմենտ/դեկրեմենտ-ը բացառություն չեն։ Պրեֆիքս տեսքը վերադարձնում է նոր արժեք, մինչ դեռ պոստֆիքը վերադարձնում է հին արժեքը (նախքան ինկրեմենտ/դեկտրեմենտ-ը). -To see the difference, here's an example: +Տարբերությունը տեսնելու համար, դիտարկենք օրինակը․ ```js run let counter = 1; @@ -356,36 +356,36 @@ let a = ++counter; // (*) alert(a); // *!*2*/!* ``` -In the line `(*)`, the *prefix* form `++counter` increments `counter` and returns the new value, `2`. So, the `alert` shows `2`. +Հետևյալ տողում `(*)`, *պրեֆիք*-ը `++counter` ավելացնում է `counter`-ի արժեքը և վերադարձնում է նոր արժեքը, `2`։ Այսպիսով `alert`-ը ցույց կտա`2`։ -Now, let's use the postfix form: +Դիտարկենք պոստֆիքս կառուցվածքը․ ```js run let counter = 1; -let a = counter++; // (*) changed ++counter to counter++ +let a = counter++; // (*) ++counter-ը ձևափոխվել է counter++ - ի alert(a); // *!*1*/!* ``` -In the line `(*)`, the *postfix* form `counter++` also increments `counter` but returns the *old* value (prior to increment). So, the `alert` shows `1`. +Հետևյալ տեղում `(*)`, *պոստվիքս* կառուցվածքը `counter++` նույնպես ավելացնում է `counter`-ի արժեքը, բայց վերադարձնում է *հին* արժեքը (նախքան ավելացումը)։ Այսպիսով `alert`-ը ցույց կտա `1`։ -To summarize: +Ամփոփում․ -- If the result of increment/decrement is not used, there is no difference in which form to use: +- Եթե ինկրեմենտ/դեկրեմենտ-ի արժեքները չեն օգտագործվում, ապա տարբերություն չկա թե որ մեկը կկիրառվի․ ```js run let counter = 0; counter++; ++counter; - alert( counter ); // 2, the lines above did the same + alert( counter ); // 2, վերը նշված տողերը իրականացնում են նույնը ``` -- If we'd like to increase a value *and* immediately use the result of the operator, we need the prefix form: +- Եթե մենք ցանկանում են ավելացնել արժեքը *և* անմիջապես օգտագործել օպերատորի արժեքը, մենք պետք է օգտագործենք պրեֆիքս կառուցվածքը․ ```js run let counter = 0; alert( ++counter ); // 1 ``` -- If we'd like to increment a value but use its previous value, we need the postfix form: +- Եթե ցանկանում ենք ավելացնել արժեքը, բայց օգտագործել նախորդ արժեքը, կարիք կա կիրառելու պոստֆիքս կառուցվածքը․ ```js run let counter = 0; @@ -393,27 +393,27 @@ To summarize: ``` ````smart header="Increment/decrement among other operators" -The operators `++/--` can be used inside expressions as well. Their precedence is higher than most other arithmetical operations. +Հետևյալ օպերատորները `++/--` կարող են կիրառվել նաև արտահայտությունների ներսում։ Նրանց գերակայությունն ավելի բարձր է, քան մյուս թվաբանական գործողություններինը։ -For instance: +Օրինակ՝ ```js run let counter = 1; alert( 2 * ++counter ); // 4 ``` -Compare with: +Համեմատել հետևյալի հետ ```js run let counter = 1; -alert( 2 * counter++ ); // 2, because counter++ returns the "old" value +alert( 2 * counter++ ); // 2, քանի որ counter++ վերադարձնում է "հին" արժեքը ``` -Though technically okay, such notation usually makes code less readable. One line does multiple things -- not good. +Չնայած տեխնիկապես սա լավ է, սովորաբար նման կիարառությունը կոդը դարձնում է քիչ ընթեռնելի։ Մի տողը կատարում է բազմաթիվ գործողություններ -- դա լավ չէ։ -While reading code, a fast "vertical" eye-scan can easily miss something like `counter++` and it won't be obvious that the variable increased. +Քանի դեռ ընթերցվում է կոդը, արագ "ուղղահայաց" դիտարկումը կարող է բաց քողնել այնպիսի բան, ինչպիսին է `counter++`-ը և ակնհայտ չի լինի, որ փոփոխականի արժեքը ավելացել է։ -We advise a style of "one line -- one action": +Մենք խորհուրդ ենք տալիս "մեկ տող -- մեկ գործողություն" ոճը: ```js run let counter = 1; @@ -422,59 +422,59 @@ counter++; ``` ```` -## Bitwise operators +## Բիթային օպերատորներ -Bitwise operators treat arguments as 32-bit integer numbers and work on the level of their binary representation. +Բիթային օպերատորները արգումենտներին վերաբերվում են որպես 32-բիթ երկարությամբ ամբողջ թվերի և աշխատում են իրենց երկուական ներկայացման մակարդակով: -These operators are not JavaScript-specific. They are supported in most programming languages. +Այս օպերատորները կոնկրետ JavaScript-ինը չեն։ Դրանք աջակցվում են ծրագրավորման լեզուների մեծ մասում։ -The list of operators: +Օպերատորների ցանկը․ -- AND ( `&` ) -- OR ( `|` ) -- XOR ( `^` ) -- NOT ( `~` ) -- LEFT SHIFT ( `<<` ) -- RIGHT SHIFT ( `>>` ) -- ZERO-FILL RIGHT SHIFT ( `>>>` ) +- և ( `&` ) +- կամ ( `|` ) +- Բացառող կամ (XOR) ( `^` ) +- ժխտում ( `~` ) +- Ձախ տեղաշարժ ( `<<` ) +- Աջ տեխաշարժ ( `>>` ) +- Զրոյի ավելացմամբ աջ տեղաշարժ ( `>>>` ) -These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises. +Այս օպերատորները շատ հազվադեպ են օգտագործվում, երբ մենք պետք է կիրառենք թվերը ամենացածր (բիթային) մակարդակում։ Մեզ այս օպերատորները շուտով պետք չեն լինի, քանի որ վեբ ծրագրավորման մեջ դրանք քիչ են օգտագործում, բայց որոշ հատուկ ոլորտներում, ինչպիսին է գաղտնագրությունը, դրանք կիրառվում են։ Անհարժեշտության դեպքում կարող եք կարդալ [Բիթային օպերատորներ](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise) հոդվածը MDN-ում։ -## Comma +## Ստորակետ -The comma operator `,` is one of the rarest and most unusual operators. Sometimes, it's used to write shorter code, so we need to know it in order to understand what's going on. +Ստորակետ օպերատորը `,` ամենահազվագյուտ և անսովոր օպերատորներից է։ Երբեմն դա օգտագործվում է ավելի կարճ կոդ գրելու համար, այնպես որ մենք պետք է դա իմանանք, որպեսզի հասկանանք, թե ինչ է կատարվում: -The comma operator allows us to evaluate several expressions, dividing them with a comma `,`. Each of them is evaluated but only the result of the last one is returned. +Հետևյալ օպերատորը թույլ է տալիս հաշվարկել մի քանի արտահայտություններ բաժանելով դրանք `,`-ով։ Նրանցից յուրաքանչյուրը հաշվարկվում է, բայց վերադարձվում է միայն վերջին արդյունքը։ -For example: +Օրինակ՝ ```js run *!* let a = (1 + 2, 3 + 4); */!* -alert( a ); // 7 (the result of 3 + 4) +alert( a ); // 7 (3 + 4-ի արդյունքը) ``` -Here, the first expression `1 + 2` is evaluated and its result is thrown away. Then, `3 + 4` is evaluated and returned as the result. +Այստես առաջին արտահայտությունը`1 + 2` վերլուծվում է, և արդյունքը անտեսվում է. Որից հետո, `3 + 4` արտահայտությունը վերլուծվում է, և վերադարձվում է որպես արդյունք։ ```smart header="Comma has a very low precedence" -Please note that the comma operator has very low precedence, lower than `=`, so parentheses are important in the example above. +Խնդրում ենք նկատի ունենալ, որ ստորակետի օպերատորը շատ ցածր առաջնահերթություն ունի, ցածր քան `=`, այնպես որ փակագծերը կարևոր են վերը նշված օրինակում։ -Without them: `a = 1 + 2, 3 + 4` evaluates `+` first, summing the numbers into `a = 3, 7`, then the assignment operator `=` assigns `a = 3`, and the rest is ignored. It's like `(a = 1 + 2), 3 + 4`. +Առանց դրանց: `a = 1 + 2, 3 + 4` վերլուծվում է `+`-ը առաջին հերթին, ստանալով `a = 3, 7`, ապա վերագրամն օպերատորը `=` վերագրում է `a = 3`, իսկ մնացածը անտեսվում է։ Դա նման է հետևյալին `(a = 1 + 2), 3 + 4`։ ``` -Why do we need an operator that throws away everything except the last expression? +Ինչու՞ է մեզ պետք օպերատոր, որը անտեսում է ամեն ինչ, բացի վերջին արտահայտությունից: -Sometimes, people use it in more complex constructs to put several actions in one line. +Երբեմն, երբեմն մարդիկ օգտագործում են դա, առավել բարդ կառուցվածքներում,մի շարք գործողություններ դնելում համար մեկ տողում։ -For example: +Օրինակ՝ ```js -// three operations in one line +// երեք օպերատորներ մեկ տողում for (*!*a = 1, b = 3, c = a * b*/!*; a < 10; a++) { ... } ``` -Such tricks are used in many JavaScript frameworks. That's why we're mentioning them. But usually they don't improve code readability so we should think well before using them. +Նման հնարքներ կիրառվում են JavaScript-ի մի շարք ֆրեյմվորկներում։ Ահա թե ինչում մենք դիտարկեցինք դրանք։ Բայց երբեմն դրանք չեն բարելավում կոդի ընթեռնելիությունը, ուստի դրանք օգտագործելուց առաջ պետք է լավ մտածել։ diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md index 632b1cf4e..7712f06bf 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/solution.md @@ -10,12 +10,12 @@ null == "\n0\n" → false null === +"\n0\n" → false ``` -Some of the reasons: +Պատճառներից որոշները. -1. Obviously, true. -2. Dictionary comparison, hence false. `"a"` is smaller than `"p"`. -3. Again, dictionary comparison, first char `"2"` is greater than the first char `"1"`. -4. Values `null` and `undefined` equal each other only. -5. Strict equality is strict. Different types from both sides lead to false. -6. Similar to `(4)`, `null` only equals `undefined`. -7. Strict equality of different types. +1. Միանշանակ, true. +2. Բառարանային համեմատություն, հետևաբար՝ false: `"a"`-ն ավելի փոքր է, քան `"p"`-ն։ +3. Կրկին բառարանային համեմատություն, առաջին նշան `"2"`-ը ավելի մեծ է, քան առաջինը նշան `"1"`-ը։ +4. `null` և `undefined` արժեքները հավասար են միայն իրար։ +5. Տարբեր տիպերի խիստ հավասարության ստուգման արդյունքը false է։ +6. Նման է `(4)`-ին, `null`-ը միայն հավասար է `undefined`-ին։ +7․ Տարբեր տիպերի խիստ հավասարության ստուգում: \ No newline at end of file diff --git a/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md b/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md index be7f75ddd..68f05da54 100644 --- a/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md +++ b/1-js/02-first-steps/09-comparison/1-comparison-questions/task.md @@ -2,9 +2,9 @@ importance: 5 --- -# Comparisons +# Համեմատություններ -What will be the result for these expressions? +Ի՞նչ են հետևյալ արտահայտությունների արժեքները: ```js no-beautify 5 > 4 @@ -15,4 +15,3 @@ undefined === null null == "\n0\n" null === +"\n0\n" ``` - diff --git a/1-js/02-first-steps/09-comparison/article.md b/1-js/02-first-steps/09-comparison/article.md index a69317fee..06c46b1ef 100644 --- a/1-js/02-first-steps/09-comparison/article.md +++ b/1-js/02-first-steps/09-comparison/article.md @@ -1,47 +1,47 @@ -# Comparisons +# Համեմատություններ -We know many comparison operators from maths. +Մենք գիտենք համեմատության բազմաթիվ գործողություններ մաթեմատիկայից։ -In JavaScript they are written like this: +JavaScript-ում դրանք գրվում են հետևյալ տեսքով․ -- Greater/less than: a > b, a < b. -- Greater/less than or equals: a >= b, a <= b. -- Equals: `a == b`, please note the double equality sign `==` means the equality test, while a single one `a = b` means an assignment. -- Not equals: In maths the notation is , but in JavaScript it's written as a != b. +- Մեծ/փոքր։ a > b, a < b։ +- Մեծ/փոքր կամ հավասար։ a >= b, a <= b։ +- Հավասար՝ `a == b`: Ուշադրություն դարձրեք, որ `==` գործողությունով ստուգվում է հավասարությունը, մինչդեռ `a = b` նշանակում է վերագրում։ +- Ոչ հավասար։ Մաթեմատիկայում այս նշանը հետևյալն է՝ , բայց JavaScript-ում այն ներկայացվում է հետևյալ տեսքով՝ a != b։ -In this article we'll learn more about different types of comparisons, how JavaScript makes them, including important peculiarities. +Այս հոդվածում մենք կսովորենք համեմատության տարբեր գործողությունները, թե ինչպես է JavaScript-ը կատարում դրանք, ներառյալ կարևոր առանձնահատկությունները։ -At the end you'll find a good recipe to avoid "JavaScript quirks"-related issues. +Վերջում դուք կիմանաք, թե ինչպես խուսափել «JavaScript-ի տարօրիանկություններ»-ի հետ կապված խնդիրներից։ -## Boolean is the result +## Արդյունքը տրամաբանական տիպի է -All comparison operators return a boolean value: +Համեմատության բոլոր գործողությունները վերադարձնում են տրամաբանական տիպի արժեք․ -- `true` -- means "yes", "correct" or "the truth". -- `false` -- means "no", "wrong" or "not the truth". +- `true` - նշանակում է "այո", "ճիշտ" կամ "իրական". +- `false` - նշանակում է "ոչ", "սխալ" կամ "ոչ իրական/կեղծ". Օրինակ․ -For example: +Օրինակ՝ ```js run -alert( 2 > 1 ); // true (correct) -alert( 2 == 1 ); // false (wrong) -alert( 2 != 1 ); // true (correct) +alert( 2 > 1 ); // true (ճիշտ) +alert( 2 == 1 ); // false (սխալ) +alert( 2 != 1 ); // true (ճիշտ) ``` -A comparison result can be assigned to a variable, just like any value: +Համեմատության արդյունքը կարելի է վերագրել փոփոխականի, ինչպես ցանկացած արժեք․ ```js run -let result = 5 > 4; // assign the result of the comparison -alert( result ); // true +let result = 5 > 4; // վերագրել համեմատության արդյունքը +alert(result); // true (ճիշտ) ``` -## String comparison +## Տողերի համեմատություն -To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order. +Եթե ցանկանում ենք ստուգել թե որ տողային փոփոխականն է մեծ, JavaScript-ը օգտագործում է այսպես կոչված "բառարան" (անգլ․՝ dictionary) կամ "բառարանային" (անգլ․՝ lexicographical) հերթականություն։ -In other words, strings are compared letter-by-letter. +Այլ կերպ ասած՝ տողերը համեմատվում են տառ առ տառ։ -For example: +Օրինակ՝ ```js run alert( 'Z' > 'A' ); // true @@ -49,55 +49,55 @@ alert( 'Glow' > 'Glee' ); // true alert( 'Bee' > 'Be' ); // true ``` -The algorithm to compare two strings is simple: +Երկու տողային փոփոխականների համեմատման ալգորիթմը շատ պարզ է․ -1. Compare the first character of both strings. -2. If the first character from the first string is greater (or less) than the other string's, then the first string is greater (or less) than the second. We're done. -3. Otherwise, if both strings' first characters are the same, compare the second characters the same way. -4. Repeat until the end of either string. -5. If both strings end at the same length, then they are equal. Otherwise, the longer string is greater. +1. Համեմատել երկու տողերի առաջին նշանները: +2․ Եթե առաջին տողի առաջին նշանը մեծ (կամ փոքր) է, քան մյուս տողինը, ապա առաջին տողը մեծ (կամ փոքր) է երկրորդից: +3. Հակառակ դեպքում, եթե տողերի առաջին նշանները հավասար են, ապա նույն ձևով համեմատվում են երկրորդ նշանները: +4. Գործողությունը կրկնվում է մինչև տողերից որևէ մեկի ավարտը։ +5. Եթե տողերն ունեն նույն երկարությունը, ապա դրանք հավասար են։ Հակառակ դեպքում, մեծ երկարություն ունեցող տողը համարվում է ավելի մեծ: -In the first example above, the comparison `'Z' > 'A'` gets to a result at the first step. +Առաջին օրինակում `'Z' > 'A'` համեմատության արդյունքը կստացվի առաջին քայլից։ -The second comparison `'Glow'` and `'Glee'` needs more steps as strings are compared character-by-character: +Երկրորդ համեմատությունը `'Glow'` և `'Glee'`, պահանջում է ավել քայլեր, քանի որ տողերը համեմատվում են նիշ առ նիշ․ -1. `G` is the same as `G`. -2. `l` is the same as `l`. -3. `o` is greater than `e`. Stop here. The first string is greater. +1. `G`-ն նույնն է ինչ `G`-ն։ +2. `l`-ը նույնն է ինչ `l`-ը։ +3. `o`-ն մեծ է քան `e`-ն։ Այստեղ համեմատթույունն ավարտվում է, քանի որ առաջին տողը ավելի մեծ է, քան երկրորդը։ -```smart header="Not a real dictionary, but Unicode order" -The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it's not exactly the same. +```smart header="Ոչ իրական բառարան, այլ Unicode-ային հերթականություն" +Վերևում բերված համեմատության ալգորիթմը մոտավորապես համարժեք է բառարաններում կամ հեռախոսագրքերում օգտագործվողին, բայց նույնը չէ: -For instance, case matters. A capital letter `"A"` is not equal to the lowercase `"a"`. Which one is greater? The lowercase `"a"`. Why? Because the lowercase character has a greater index in the internal encoding table JavaScript uses (Unicode). We'll get back to specific details and consequences of this in the chapter . +Օրինակ՝ մեծատառ `"A"`-ն հավասար չէ փոքրատառ `"a"`-ին։ Ո՞ր մեկն է մեծ. փոքրատառ `"a"`-ն։ Ինչու՞, քանի որ փոքրատառ նշանը ունի ավելի մեծ ինդեքս կոդավորման աղյուսակում, որն օգտագործում է JavaScript-ը (Unicode)։ Մենք կվերադառնանք սրա մանրամասներին, և բխող հետևանքներին բաժնում։ ``` -## Comparison of different types +## Տարբեր տիպերի համեմատությունը -When comparing values of different types, JavaScript converts the values to numbers. +Երբ համեմատությունը կատարվում է տարբեր տիպերի միջև, JavaScript-ը դրանք ձևափոխում է թվի: -For example: +Օրինակ՝ ```js run -alert( '2' > 1 ); // true, string '2' becomes a number 2 -alert( '01' == 1 ); // true, string '01' becomes a number 1 +alert( '2' > 1 ); // true, տողային '2' փոփոխականը ձևափոխվում է թվային 2-ի +alert( '01' == 1 ); // true, տողային '01' փոփոխականը ձևափոխվում է թվային 1-ի ``` -For boolean values, `true` becomes `1` and `false` becomes `0`. +Տրամաբանական արժեքների դեպքում `true`-ն ձևափոխվում է `1`-ի, իսկ `false`-ը՝ `0`-ի։ -For example: +Օրինակ՝ ```js run alert( true == 1 ); // true alert( false == 0 ); // true ``` -````smart header="A funny consequence" -It is possible that at the same time: +````smart header="Հետաքրքիր հետևանք" +Միաժամանակ հնարավոր է․ -- Two values are equal. -- One of them is `true` as a boolean and the other one is `false` as a boolean. + - Երկու արժեքներ նույնն են։ + - Նրանցից մեկը տրամաբանական `true`-է, իսկ մյուսը տրամաբանական `false`-է։ -For example: +Օրինակ՝ ```js run let a = 0; @@ -109,67 +109,67 @@ alert( Boolean(b) ); // true alert(a == b); // true! ``` -From JavaScript's standpoint, this result is quite normal. An equality check converts values using the numeric conversion (hence `"0"` becomes `0`), while the explicit `Boolean` conversion uses another set of rules. +JavaScript-ի տեսանկյունից, այս արդյունքները համարվում են ճիշտ։ Տողային արժեքը ձևափոխվում է թվային տիպի (ուստի `"0"`-ն ձևափոխվում է `0`-ի), մինչդեռ բացահայտ `Boolean`-փոխակերպումը կիրառում է մեկ այլ կանոն։ ```` -## Strict equality +## Խիստ հավասարություն -A regular equality check `==` has a problem. It cannot differentiate `0` from `false`: +Սովորական հավասարության ստուգումը `==` խնդրահարույց է։ Այն չի կարող տարբերակել `0`-ն `false`-ից։ ```js run alert( 0 == false ); // true ``` -The same thing happens with an empty string: +Նույն բանը կատարվում է դատարկ տողի հետ։ ```js run alert( '' == false ); // true ``` -This happens because operands of different types are converted to numbers by the equality operator `==`. An empty string, just like `false`, becomes a zero. +Սա պատահում է, քանի որ `==` գործողությանը տարբեր տիպերի համեմատման ժամանակ արժեքները ձևափոխում է թվերի։ Դատարկ տողը, ինչպես `false`-ը, դառնում է զրո։ -What to do if we'd like to differentiate `0` from `false`? +Ի՞նչ պետք է անել, եթե ցանկանում ենք տարբերակել `0`-ն `false`-ից։ -**A strict equality operator `===` checks the equality without type conversion.** +**Խիստ համեմատության գործողությունը `===` ստուգում է հավասարությունը առանց տիպային կերպափոխումների:** -In other words, if `a` and `b` are of different types, then `a === b` immediately returns `false` without an attempt to convert them. +Այլ կերպ ասած, եթե `a`-ն և `b`-ն տարբերի տիպերի են, ապա `a === b`-ն անմիջապես կվերադարձնի `false`, առանց տիպերի կերպափոխման։ -Let's try it: +Եկեք փորձենք դա․ ```js run -alert( 0 === false ); // false, because the types are different +alert(0 === false); // false, քանի որ արժեքները ունեն տարբեր տիպեր ``` -There is also a "strict non-equality" operator `!==` analogous to `!=`. +Գոյություն ունի "խիստ ոչ հավասար" գործողության նշանը `!==`, որը նման է `!=`-ին։ -The strict equality operator is a bit longer to write, but makes it obvious what's going on and leaves less room for errors. +Խիստ հավասարության օպերատորը մի փոքր ավելի երկար է գրվում, բայց ակնհայտ է դառնում այն, որ դա ավելի քիչ է սխալներ առաջացնում։ -## Comparison with null and undefined +## Համեմատություն null-ի և undefined-ի հետ -There's a non-intuitive behavior when `null` or `undefined` are compared to other values. +Գոյություն ունի ոչ ինտուիտիվ պահվածք, երբ `null`-ը կամ `undefined`-ը համեմատվում են այլ արժեքների հետ։ -For a strict equality check `===` -: These values are different, because each of them is a different type. +Խիստ համեմատության `===` դեպքում․ +այս արժեքները տարբեր են, քանի որ նրանցից մեկը ունի այլ տիպ ```js run alert( null === undefined ); // false ``` -For a non-strict check `==` -: There's a special rule. These two are a "sweet couple": they equal each other (in the sense of `==`), but not any other value. +Ոչ խիստ համեմատության `==` դեպքում․ +Գոյություն ունի հատուկ կանոն։ Այս երկուսը համահունչ են, դրանք հավասար են իրար հետ, բայց հավասար չեն ոչ արժեքներով։ ```js run alert( null == undefined ); // true ``` -For maths and other comparisons `< > <= >=` -: `null/undefined` are converted to numbers: `null` becomes `0`, while `undefined` becomes `NaN`. +Մաթեմատիկական և այլհամեմատություններում `< > <= >=`․ +`null/undefined`-ը ձևափոխվում են թվերի, `null`-ը ձևափոխվում է `0`-ի, մինչդեռ `undefined`-ը ձևափոխվում է `NaN`-ի։ -Now let's see some funny things that happen when we apply these rules. And, what's more important, how to not fall into a trap with them. +Այժմ եկեք դիտարկենք մի քանի հետաքրքիր բաներ, որոնք տեղի են ունենում, երբ կիրառում ենք այս կանոնները: Եվ, որ ավելի կարևոր է, ինչպես չնկնել այդ ծուղակը։ -### Strange result: null vs 0 +### Տարօրինակ արդյունք․ null vs 0 -Let's compare `null` with a zero: +Եկեք համեմատենք `null`-ը զրոյի հետ․ ```js run alert( null > 0 ); // (1) false @@ -177,15 +177,15 @@ alert( null == 0 ); // (2) false alert( null >= 0 ); // (3) *!*true*/!* ``` -Mathematically, that's strange. The last result states that "`null` is greater than or equal to zero", so in one of the comparisons above it must be `true`, but they are both false. +Մաթեմատիկորեն, դա տարօրինակ է։ Վերջին արդյունքը, որ «`null`-ը մեծ կամ հավասար է զրոյի», համեմատություններից գոնե մեկը պետք է լինի `true`, բայց երկուսն էլ սխալ են։ -The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, treating it as `0`. That's why (3) `null >= 0` is true and (1) `null > 0` is false. +Դրա պատճառըն այն է, որ `==` և `> < >= <=` գործողությունները գործում են տարբեր։ Հավասարության ստուգումը կերպափոխում է `null`-ը թվի, այսինքն՝ 0-ի։ Ահա թե ինչու `null >= 0`-ն ճիշտ է, իսկ `null > 0`-ը սխալ։ -On the other hand, the equality check `==` for `undefined` and `null` is defined such that, without any conversions, they equal each other and don't equal anything else. That's why (2) `null == 0` is false. +Մյուս կողմից, `==`-ը ստուգում է `undefined`-ը և `null`-ը առանց ձևափոխման, դրանք հավասար են միմյանց, բայց հավասար չեն այլ փոփոխականի, ահա թե ինչու `null == 0` արտահայտությունը արժեքը `false` է: -### An incomparable undefined +### Անհամեմատելի undefined-ը -The value `undefined` shouldn't be compared to other values: +`undefined` արժեքը չի կարող համեմատվել այլ արժեքների հետ․ ```js run alert( undefined > 0 ); // false (1) @@ -193,24 +193,24 @@ alert( undefined < 0 ); // false (2) alert( undefined == 0 ); // false (3) ``` -Why does it dislike zero so much? Always false! +Ինչու՞ այն նման չէ զրոյին, համեմատության արդյունքը միշտ կեղծ է: -We get these results because: +Մենք ստանում ենք այս արդյունքը, քանի որ․ -- Comparisons `(1)` and `(2)` return `false` because `undefined` gets converted to `NaN` and `NaN` is a special numeric value which returns `false` for all comparisons. -- The equality check `(3)` returns `false` because `undefined` only equals `null`, `undefined`, and no other value. +- Համեմատություններ `(1)`-ը և `(2)`-ը վերադարձնում են `false`, քանի որ `undefined`-ը ձևափոխվում է `NaN`-ի, իսկ `NaN`-ը հատուկ թվային արժեք է, որը բոլոր համեմատությունների դեպքում վերադարձնում է `false`։ +- Համեմատություն `(3)`-ը վերադարձնում է `false`, քանի որ `undefined`-ը հավասար է միայն `null`-ին և `undefined`-ին, և ոչ մի այլ արժեքի: -### Avoid problems +### Խուսափեք խնդիրներից -Why did we go over these examples? Should we remember these peculiarities all the time? Well, not really. Actually, these tricky things will gradually become familiar over time, but there's a solid way to avoid problems with them: +Ինչու՞ դիտարկեցինք այս օրինակները: Պե՞տք է անընդհատ հիշել այս առանձնահատկությունները: Դե, իրականում ոչ: Փաստորեն, նմանատիպ բարդությունները ժամանակի ընթացքում աստիճանաբար հայտնի կդառնան, բայց այդ խնդիրներից խուսափելու հնարավոր միջոցներ կան. -- Treat any comparison with `undefined/null` except the strict equality `===` with exceptional care. -- Don't use comparisons `>= > < <=` with a variable which may be `null/undefined`, unless you're really sure of what you're doing. If a variable can have these values, check for them separately. +- Ցանկացած համեմատությանը `undefined/null`-ի հետ, բացի խիստ հավասարությունից, հարկավոր է հատուկ ուշադրություն։ +- Մի օգտագործեք `>= > < <=` համեմատությունները այն արժեքների հետ, որոնք կարող են լինել `null/undefined`, եթե իսկապես վստահ չեք, թե ինչ եք անում։ Եթե փոփոխականը կարող է ունենալ այս արժեքները, ստուգեք դրանք առանձին: -## Summary +## Ամփոփում -- Comparison operators return a boolean value. -- Strings are compared letter-by-letter in the "dictionary" order. -- When values of different types are compared, they get converted to numbers (with the exclusion of a strict equality check). -- The values `null` and `undefined` equal `==` each other and do not equal any other value. -- Be careful when using comparisons like `>` or `<` with variables that can occasionally be `null/undefined`. Checking for `null/undefined` separately is a good idea. +- Համեմատման գործողությունները վերադարձնում են տրամաբանական արժեք: +- Տողերը համեմատվում են տառ առ տառ, բառարանային հերթականությամբ: +- Երբ տարբեր տիպեր ունեցող արժեքները համեմատվում են, դրանք ձևափոխվում են թվերի (բացառությամբ խիստ հավասարության համեմատության): +- `null` և `undefined` արժեքները հավասար են (`==`) մեկը մյուսին և հավասար չեն որևէ այլ արժեքի: +- Զգուշացեք օգտագործել այնպիսի համեմատություններ ինչպիսիք են `>`, կամ `<` այն փոփոխականների հետ, որոնք կարող են լինել `null/undefined`։ Լավ գաղափար է `null/undefined`-ը ստուգել առանձին։ diff --git a/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md b/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md index 51f1d4680..406ff73c0 100644 --- a/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md +++ b/1-js/02-first-steps/10-ifelse/1-if-zero-string/solution.md @@ -1,12 +1,12 @@ -**Yes, it will.** +**Այո, կցուցադրվի:** -Any string except an empty one (and `"0"` is not empty) becomes `true` in the logical context. +Ցանկացած տող, բացի դատարկից (իսկ `"0"`-ն դատարկ չէ) տրամաբանական համատեքստում դառնում է `true`: -We can run and check: +Մենք կարող ենք գործարկել և ստուգել. ```js run if ("0") { - alert( 'Hello' ); + alert( 'Ողջույն' ); } ``` diff --git a/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md b/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md index 5f16cda85..88820ffa5 100644 --- a/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md +++ b/1-js/02-first-steps/10-ifelse/1-if-zero-string/task.md @@ -1,14 +1,14 @@ -importance: 5 +կարևորությունը՝ 5 --- -# if (a string with zero) +# if (զրոյով տող) -Will `alert` be shown? +Կցուցադրվի՞ արդյոք `alert`-ը: ```js if ("0") { - alert( 'Hello' ); + alert( 'Ողջույն' ); } ``` diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg index 47b020aab..422be45cc 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2.svg @@ -1 +1 @@ -BeginYou don't know? “ECMAScript”!Right!What's the “official” name of JavaScript?OtherECMAScript \ No newline at end of file +BeginYou don't know? “ECMAScript”!Right!What's the “official” name of JavaScript?OtherECMAScript diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html index ea9966653..e9cda3bf3 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/ifelse_task2/index.html @@ -5,12 +5,12 @@ diff --git a/1-js/02-first-steps/10-ifelse/2-check-standard/task.md b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md index 4305584fa..ce72e7cce 100644 --- a/1-js/02-first-steps/10-ifelse/2-check-standard/task.md +++ b/1-js/02-first-steps/10-ifelse/2-check-standard/task.md @@ -1,12 +1,12 @@ -importance: 2 +կարևորությունը՝ 2 --- -# The name of JavaScript +# JavaScript-ի անվանումը -Using the `if..else` construct, write the code which asks: 'What is the "official" name of JavaScript?' +Օգտագործելով `if..else` կառուցվածքը, գրեք կոդ, որը կհարցնի. «Ո՞րն է JavaScript-ի «պաշտոնական» անվանումը:»։ -If the visitor enters "ECMAScript", then output "Right!", otherwise -- output: "You don't know? ECMAScript!" +Եթե այցելուն մուտքագրում է «ECMAScript», ապա արտատպեք «Ճիշտ է:», հակառակ դեպքում՝ արտատպեք «Դուք չգիտե՞ք. ECMAScript:»: ![](ifelse_task2.svg) diff --git a/1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html b/1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html index f168360dd..3a7684e0b 100644 --- a/1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html +++ b/1-js/02-first-steps/10-ifelse/3-sign/if_sign/index.html @@ -6,7 +6,7 @@