0% found this document useful (0 votes)
3 views6 pages

Javascript Guide

Uploaded by

demirkk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Javascript Guide

Uploaded by

demirkk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript - Temel Kodlar, Fonksiyon Türleri, Birle■me/Yaz■m Olas■l■klar■

======================================================================

■çindekiler
1. Giri■
2. De■i■kenler: var, let, const
3. Veri Tipleri ve Dönü■ümler
4. Operatörler
5. Kontrol Yap■lar■ (if, switch, for, while)
6. Fonksiyonlar
- Fonksiyon bildirimleri (Function Declaration)
- Fonksiyon ifadeleri (Function Expression)
- Arrow fonksiyonlar
- Immediately Invoked Function Expression (IIFE)
- Generator fonksiyonlar
- Async fonksiyonlar
- Callback vs Promise vs async/await
7. Fonksiyonlar■n birle■me/kompozisyon yöntemleri
- compose ve pipe örnekleri
- higher-order functions (map, filter, reduce)
8. Obje ve Prototip
- Prototip kal■t■m■
- ES6 Class sözdizimi
9. Modüller
- ES Modules (import/export)
- CommonJS (require/[Link])
- Birle■tirme, paketleme (webpack/rollup/esbuild - k■sa not)
10. Hata yönetimi (try/catch/finally, throwing)
11. Asenkronite: Event Loop, Microtasks & Macrotasks
12. Yaz■m alternatifleri ve stil örnekleri
- Function vs Arrow
- Optional chaining
- Nullish coalescing
- Ternary vs if
13. ■yi uygulamalar
14. K■sa örnekler (kod bloklar■)
15. Ek kaynaklar

------------------------------------------------------------
1. Giri■
------------------------------------------------------------
JavaScript, taray■c■da ve sunucuda ([Link]) çal■■an dinamik, yüksek seviyeli bir programlama
dilidir.
A■a■■da temel yap■ ta■lar■ ve farkl■ yaz■m olas■l■klar■na örnekler bulacaks■n■z.

------------------------------------------------------------
2. De■i■kenler: var, let, const
------------------------------------------------------------
- var: fonksiyon scope; hoisting uygulan■r.
- let: blok scope; yeniden atanabilir.
- const: blok scope; yeniden atanamaz (ancak obje içeri■i de■i■tirilebilir).

Örnek:
```js
var a = 1;
let b = 2;
const c = 3;
```

------------------------------------------------------------
3. Veri Tipleri ve Dönü■ümler
------------------------------------------------------------
- Temel tipler: number, string, boolean, null, undefined, symbol, bigint
- Referans tipler: object, array, function
- Tür dönü■ümleri: String(), Number(), Boolean(), parseInt, parseFloat, toString()

------------------------------------------------------------
4. Operatörler
------------------------------------------------------------
- Aritmetik, kar■■la■t■rma, mant■ksal, bitwise, ternary, spread/rest, destructuring

Örnek spread:
```js
const arr = [1,2,3];
const arr2 = [...arr,4];
```

------------------------------------------------------------
5. Kontrol Yap■lar■
------------------------------------------------------------
- if / else, switch, for, for...of, for...in, while, do...while

------------------------------------------------------------
6. Fonksiyonlar
------------------------------------------------------------
Fonksiyon Bildirimi:
```js
function add(a, b) {
return a + b;
}
```

Fonksiyon ■fadesi:
```js
const add = function(a, b) {
return a + b;
}
```

Arrow Fonksiyon:
```js
const add = (a, b) => a + b;
```

IIFE:
```js
(function() {
[Link]('IIFE çal■■t■');
})();
```

Generator:
```js
function* gen() {
yield 1;
yield 2;
}
```

Async:
```js
async function fetchData() {
const res = await fetch('/api');
return [Link]();
}
```

Callback vs Promise vs Async/Await:


- Callback: geleneksel, callback hell riski
- Promise: then/catch zinciri
- async/await: Promise tabanl■, daha okunur

------------------------------------------------------------
7. Fonksiyonlar■n birle■me / kompozisyon yöntemleri
------------------------------------------------------------
Compose (sa■a do■ru) ve pipe (soldan sa■a) fonksiyonlar■:

```js
const compose = (...fns) => x => [Link]((v, f) => f(v), x);
const pipe = (...fns) => x => [Link]((v, f) => f(v), x);

// Örnek:
const double = x => x * 2;
const inc = x => x + 1;
const f = compose(double, inc); // double(inc(x))
f(3); // 8
```

Higher-order functions:
- map, filter, reduce: dizilerle fonksiyonel programlama.

------------------------------------------------------------
8. Obje ve Prototip
------------------------------------------------------------
Prototip temelli kal■t■m; ES6 class sözdizimi sugar sa■lar.

```js
function Person(name) {
[Link] = name;
}
[Link] = function() { return 'Hi ' + [Link]; }

class PersonClass {
constructor(name) { [Link] = name; }
greet() { return `Hi ${[Link]}`; }
}
```

------------------------------------------------------------
9. Modüller
------------------------------------------------------------
ES Modules:
```js
// export
export function foo() {}
export default function() {}
// import
import foo from './[Link]';
import { bar } from './[Link]';
```

CommonJS:
```js
const foo = require('./foo');
[Link] = foo;
```

Bundling: webpack/rollup/esbuild kullan■larak modüller tek dosyada birle■tirilir.

------------------------------------------------------------
10. Hata yönetimi
------------------------------------------------------------
```js
try {
risky();
} catch (err) {
[Link](err);
} finally {
cleanup();
}
```

Throw:
```js
throw new Error('Bir hata olu■tu');
```

------------------------------------------------------------
11. Asenkronite: Event Loop
------------------------------------------------------------
- Call stack, callback queue, microtask queue (Promise .then, async/await)
- setTimeout/setInterval makrotask; Promise-then microtask -> microtasks önce i■lenir

------------------------------------------------------------
12. Yaz■m alternatifleri ve stil örnekleri
------------------------------------------------------------
- Fonksiyon bildirimleri ve ifade farklar■ (hoisting)
- Arrow fonksiyonlar 'this' ba■lam■n■ ba■lamaz (lexical this)
- Optional chaining: obj?.prop
- Nullish coalescing: a ?? b
- Short-circuit: a && [Link]

Örnek:
```js
const name = user?.profile?.name ?? 'Anonim';
```
------------------------------------------------------------
13. ■yi uygulamalar
------------------------------------------------------------
- const ile ba■la, let gerekti■inde
- Saf fonksiyonlar
- Küçük modüller
- Error handling yap
- Test yaz
- Linters (ESLint) kullan

------------------------------------------------------------
14. K■sa örnekler
------------------------------------------------------------
Debounce:
```js
function debounce(fn, wait) {
let t;
return function(...args) {
clearTimeout(t);
t = setTimeout(() => [Link](this, args), wait);
}
}
```

Memoize:
```js
const memoize = fn => {
const cache = new Map();
return (...args) => {
const key = [Link](args);
if ([Link](key)) return [Link](key);
const res = fn(...args);
[Link](key, res);
return res;
}
}
```

Fetch with timeout (promise race):


```js
function fetchWithTimeout(url, ms) {
return [Link]([
fetch(url),
new Promise((_, rej) => setTimeout(() => rej(new Error('timeout')), ms))
]);
}
```

------------------------------------------------------------
15. Ek kaynaklar
------------------------------------------------------------
- MDN Web Docs
- ECMAScript specification
- You Don't Know JS (book series)
- [Link] docs

------------------------------------------------------------
Notlar
- Bu doküman hem ba■lang■ç hem orta seviye geli■tiriciler için çe■itli yaz■m örnekleri,
fonksiyon türleri, birle■tirme/kompozisyon teknikleri ve asenkronite hakk■nda özet bilgiler
içerir.
- E■er istersen, bu içeri■i geni■letebilir, her ba■l■k için daha fazla örnek ekleyebilir veya
örnek projelerle zenginle■tirebilirim.

You might also like