1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
'use strict'; var x = 5; console.log(x); //5 console.log(y); // undefined. var y = 6; let z = 12; console.log(z); //12 //console.log(m); //Cannot access 'm' before initialization let m = 15; //console.log(n); //Cannot access 'm' before initialization const n = 4; add1(); //4 function add1() { const x = 2, y = 2; console.log(x + y); } add1(); //4 //addTwo(); //ReferenceError: Cannot access 'addTwo' before initialization const addTwo = function () { const x = 3, y = 3; console.log(x + y); }; addTwo(); //6 console.log('*** Kurs Örnekleri Variable ***'); // Kurs Örneği. console.log(me); // undefined // TDZ Time Dead Zone - Ölü Bölge // console.log(job); //cannot access job before initialization // console.log(year); //cannot access year before initialization var me = 'Jonas'; let job = 'teacher'; const year = 1991; console.log('*** Kurs Örnekleri Functions ***'); // Kurs Örneği. console.log(addDecl(2, 2)); //4 // console.log(addExp(2, 2)); //Cannot access 'addExp' before initialization //console.log(addArrow(2, 2)); //Cannot access 'addExp' before initialization function addDecl(a, b) { return a + b; } // const tanımlandığından dolayı const addExp = function (a, b) { return a + b; }; // const tanımladığından dolayı const addArrow = (a, b) => a + b; function calcAge(birthYear) { const age = 2037 - birthYear; function printAge() { const firstName = 'Luck'; const output = `${firstName}, you are ${age} ,born in ${birthYear}`; console.log(output); } function add(a, b) { const y = 'y'; const x = a + b; console.log(x); } console.log(y); add(2, 3); printAge(); return age; } const firstName = 'Jonas'; calcAge(1991); //printAge(); // reference error //console.log(age); // reference error var globalVar = 'Ben global bir değişkenim.'; function outerFunction() { var outerVar = 'Ben dıştaki bir değişkenim.'; function middleFunction() { var middleVar = 'Ben ortadaki bir değişkenim.'; function innerFunction() { var innerVar = 'Ben içteki bir değişkenim.'; console.log(globalVar); // Global değişkene erişim console.log(outerVar); // Dıştaki değişkene erişim console.log(middleVar); // Orta değişkene erişim console.log(innerVar); // İçteki değişkene erişim } innerFunction(); // innerVar burada kullanılamaz, çünkü bu kapsam dışında console.log(innerVar); // ReferenceError: innerVar is not defined } middleFunction(); // middleVar burada kullanılamaz, çünkü bu kapsam dışında console.log(middleVar); // ReferenceError: middleVar is not defined } outerFunction(); // outerVar burada kullanılamaz, çünkü bu kapsam dışında console.log(outerVar); // ReferenceError: outerVar is not defined |
İlk Yorumu Siz Yapın