|
1 | | -# The modern mode, "use strict" |
| 1 | +# Müasir Rejim, "use strict" |
2 | 2 |
|
3 | | -For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change. |
| 3 | +JavaScript uzun müddət ərzində uyğunsuzluq problemləri olmadan inkişaf etdi. Köhnə xüsusiyyətlər dəyişdirilmədən, dilə yeni xüsusiyyətlər əlavə olundu. |
4 | 4 |
|
5 | | -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. |
| 5 | +Bunun üstünlüyü mövcud kodun işləmə qabiliyyətini heç vaxt pozmaması idi. Lakin mənfi tərəfi o idi ki, JavaScript'in yaradıcılarının etdiyi hərhansı bir səhv və ya düzgün olmayan bir qərar dilin daimi bir hissəsinə çevrilirdi. |
6 | 6 |
|
7 | | -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"`. |
| 7 | +Bu vəziyyət 2009-cu ildə ECMAScript 5 (ES5) standartı təqdim edilənə qədər davam etdi. ES5 dilə yeni xüsusiyyətlər əlavə etdi və mövcud olan bəzi xüsusiyyətləri dəyişdirdi. Köhnə kodların işləməyə davam etməsi üçün bir çox dəyişikliklər susqunluq halında (by default) deaktiv edilmişdi. Bu dəyişiklikləri aktiv etmək üçün xüsusi bir direktivdən istifadə etməlisiniz: `"use strict"`. |
8 | 8 |
|
9 | 9 | ## "use strict" |
10 | 10 |
|
11 | | -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. |
| 11 | +Bu direktiv bir string kimi görünür: `"use strict"` və ya `'use strict'`. Əgər bu direktiv bir skriptin ən üst hissəsində yerləşdirilərsə, həmin skript "müasir" qaydada işləyir. |
12 | 12 |
|
13 | | -For example: |
| 13 | +Məsələn: |
14 | 14 |
|
15 | 15 | ```js |
16 | 16 | "use strict"; |
17 | 17 |
|
18 | | -// this code works the modern way |
| 18 | +// bu kod müasir qaydada işləyir |
19 | 19 | ... |
20 | 20 | ``` |
21 | 21 |
|
22 | | -We will learn functions (a way to group commands) soon. Looking ahead, let's note that `"use strict"` can be put at the beginning of the function body instead of the whole script. Doing that enables strict mode in that function only. But usually, people use it for the whole script. |
| 22 | +Biz funksiyaları (ifadələri qruplaşdırmaq üçün bir yoldur) tezliklə öyrənəcəyik. İndilik isə qeyd etməliyik ki, `"use strict"` direktivini skriptin ən üstündə yerləşdirmək əvəzinə, bir funksiyanın başlanğıcına da əlavə etmək mümkündür. Bu halda yalnız həmin funksiya müasir qaydada işləyəcək. Lakin, adətən insanlar bu direktivi bütün skript üçün istifadə edirlər. |
23 | 23 |
|
| 24 | +````warn header="\"use strict\" direktivinin ən üstdə olduğundan əmin olun" |
| 25 | +Əmin olun ki, `"use strict"` direktivi skriptinizin ən üst hissəsində yerləşir, əks halda sıx rejim aktivləşməyəcək. |
24 | 26 |
|
25 | | -````warn header="Ensure that \"use strict\" is at the top" |
26 | | -Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled. |
27 | | - |
28 | | -Strict mode isn't enabled here: |
| 27 | +Burada sıx rejim aktiv deyil: |
29 | 28 |
|
30 | 29 | ```js no-strict |
31 | | -alert("some code"); |
32 | | -// "use strict" below is ignored--it must be at the top |
| 30 | +alert("bəzi kodlar"); |
| 31 | +// "use strict" aşağıda yerləşdiyindən nəzərə alınmayacaq -- o mütləq ən yuxarıda olmalıdır |
33 | 32 |
|
34 | 33 | "use strict"; |
35 | 34 |
|
36 | | -// strict mode is not activated |
| 35 | +// sıx rejim aktiv deyil |
37 | 36 | ``` |
38 | 37 |
|
39 | | -Only comments may appear above `"use strict"`. |
| 38 | +Sadəcə şərhlər `"use strict"` direktivindən əvvəl yerləşdirilə bilər. |
40 | 39 | ```` |
41 | 40 |
|
42 | | -```warn header="There's no way to cancel `use strict`" |
43 | | -There is no directive like `"no use strict"` that reverts the engine to old behavior. |
| 41 | +```warn header="`use strict` rejimini deaktiv etmək mümkün deyil" |
| 42 | +Sıx rejimi deaktiv etmək üçün `"no use strict"` kimi bir direktiv mövcud deyil. |
44 | 43 |
|
45 | | -Once we enter strict mode, there's no going back. |
| 44 | +Bir dəfə sıx rejim aktivləşdikdən sonra, geri dönüş mümkün deyil. |
46 | 45 | ``` |
47 | 46 |
|
48 | | -## Browser console |
| 47 | +## Brauzer Konsolu |
49 | 48 |
|
50 | | -For the future, when you use a browser console to test features, please note that it doesn't `use strict` by default. |
| 49 | +Gələcəkdə brauzerin konsolundan xüsusiyyətləri test etmək üçün istifadə etdikdə unutmayın ki, konsol susqunluq halında `use strict` rejimini aktivləşdirmir. |
51 | 50 |
|
52 | | -Sometimes, when `use strict` makes a difference, you'll get incorrect results. |
| 51 | +Bəzən, `use strict` rejimi ilə fərqlər yaranır və nəticədə yanlış nəticələr əldə edə bilərsiniz. |
53 | 52 |
|
54 | | -You can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this: |
| 53 | +`key:Shift+Enter` kombinasiyasından istifadə edərək çoxsətirli kod daxil edib `use strict` direktivini ən üstünə yerləşdirin. Məsələn: |
55 | 54 |
|
56 | 55 | ```js |
57 | | -'use strict'; <Shift+Enter for a newline> |
58 | | -// ...your code |
59 | | -<Enter to run> |
| 56 | +'use strict'; <Shift+Enter ilə yeni sətir əlavə edin> |
| 57 | +// ...sizin kod |
| 58 | +<İcra etmək üçün Enter> |
60 | 59 | ``` |
61 | 60 |
|
62 | | -It works in most browsers, namely Firefox and Chrome. |
| 61 | +Bu metod əksər brauzerlərdə, məsələn, Firefox və Chrome'da işləyir. |
63 | 62 |
|
64 | | -If it doesn't, the most reliable way to ensure `use strict` would be to input the code into console like this: |
| 63 | +Əgər bu işləməzsə, ən etibarlı yol `use strict` rejimini aşağıdakı nümunədə göstərildiyi kimi istifadə etməkdir: |
65 | 64 |
|
66 | 65 | ```js |
67 | 66 | (function() { |
68 | 67 | 'use strict'; |
69 | 68 |
|
70 | | - // ...your code... |
| 69 | + // ...sizin kod... |
71 | 70 | })() |
72 | 71 | ``` |
73 | 72 |
|
74 | | -## Always "use strict" |
| 73 | +## Hər Zaman "use strict" |
75 | 74 |
|
76 | | -We have yet to cover the differences between strict mode and the "default" mode. |
| 75 | +Biz hələ sıx rejim ilə "default" rejim arasındakı fərqləri tam əhatə etməmişik. |
77 | 76 |
|
78 | | -In the next chapters, as we learn language features, we'll note the differences between the strict and default modes. Luckily, there aren't many and they actually make our lives better. |
| 77 | +Növbəti fəsillərdə dil xüsusiyyətlərini öyrəndikcə, sıx rejim və defolt rejim arasındakı fərqləri vurğulayacağıq. Xoşbəxtlikdən, bu fərqlər azdır və həyatımızı daha da asanlaşdırır. |
79 | 78 |
|
80 | | -For now, it's enough to know about it in general: |
| 79 | +İndilik, aşağıdakıları bilmək kifayətdir: |
81 | 80 |
|
82 | | -1. The `"use strict"` directive switches the engine to the "modern" mode, changing the behavior of some built-in features. We'll see the details later in the tutorial. |
83 | | -2. Strict mode is enabled by placing `"use strict"` at the top of a script or function. Several language features, like "classes" and "modules", enable strict mode automatically. |
84 | | -3. Strict mode is supported by all modern browsers. |
85 | | -4. We recommended always starting scripts with `"use strict"`. All examples in this tutorial assume strict mode unless (very rarely) specified otherwise. |
| 81 | +1. `"use strict"` direktivi mühərriki sıx rejimə keçirir və bəzi daxili xüsusiyyətlərin davranışını dəyişir. Bunun detallarını daha sonra dərslikdə öyrənəcəyik. |
| 82 | +2. `"use strict"` direktivini skriptin və ya funksiyanın ən üstünə yerləşdirərək sıx rejimi aktivləşdirə bilərsiniz. "Siniflər" ("classes") və "modullar" ("modules") kimi bəzi dil xüsusiyyətləri sıx rejimi avtomatik aktivləşdirir. |
| 83 | +3. Sıx rejim bütün müasir brauzerlər tərəfindən dəstəklənir. |
| 84 | +4. Tövsiyə olunur ki, bütün skriptlərinizə `"use strict"` ilə başlayasınız. Bu dərslikdəki nümunələrin hamısı, başqa cür göstərilmədiyi təqdirdə (çox nadir hallarda), sıx rejimi nəzərdə tutur. |
0 commit comments