Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions 1.0.0-variables.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* VAR: Global Variable */

var name = "Global Variable";

function Func() {
var name = "Local Variable";
console.log(name); // Local Variable
}
console.log(name); // Global Variable


/* ==================================== */


var name2 = "Global Variable";
console.log(name2); // Global Variable

function Func2() {
name2 = "Local Variable";
console.log(name2);
}
Func2(); // Local Variable
console.log(name2); // Local Variable


/* ==================================== */


/* CONST: Constant Variable */

const pi = 3;
console.log(pi); // 3

pi = 3.14;
console.log(pi); // ERROR: Uncaught TypeError: Assignment to constant variable. (Sabit değişken olduğu için değer atanamaz)


/* ==================================== */


const pi2 = 3;
console.log(pi2); // 3

const pi2 = 3.14;
console.log(pi2); // ERROR: Uncaught SyntaxError: Identifier 'pi' has already been declared (Daha önce tanımlandı, dolayısıyla tekrar tanımlanamaz. )


/* ==================================== */


/* LET: Block-Scope Variable */


let age = 15;
console.log(age); // 15

age = 20;
console.log(age); // 20


/* ==================================== */


let arr = 15;
console.log(age2); // 15

let age2 = 20;
console.log(age2); // ERROR: Uncaught SyntaxError: Identifier 'age' has already been declared (Daha önce tanımlandı, dolayısıyla tekrar tanımlanamaz. )


/* ==================================== */


for(let i = 0; i < 5; i++){
console.log(i);
// 0, 1, 2, 3, 4
}
console.log(i);
// i is not defined


35 changes: 35 additions & 0 deletions 1.0.1-template_literal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Template Literal backtick( ` ) */

const name = "Ali";
console.log(`Merhaba ${name}`);
// Merhaba Ali

/* ==================================== */

const obj = {
name: "Ali "
};
console.log(`Merhaba ${obj.name}`);
// Merhaba Ali

/* ==================================== */

const getName = () => { return "Ali" }
console.log(`Merhaba ${getName()}`);
// Merhaba Ali

/* ==================================== */

function selamla(str, nameArg) { // str: ["Merhaba ",""]
return `selamlar! hoşgeldin ${nameArg}`;
}
let name = "Ali";
selamla`Merhaba ${name}`;
// selamlar! hoşgeldin Ali

/* ==================================== */

var a = 5;
var b = 10;
console.log (`${a}+${b} toplam.:"${a+b}"`);
//5 + 10 toplamı..:"15"
109 changes: 109 additions & 0 deletions 1.0.2-arrow_functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* Arrow Functions */

/* ES5 */
function hello() {
return "Hello World!";
}

/* ES6 */
hello = () => "Hello World!"


/* ==================================== */


/* ES5 */
let sum = function (x, y) {
return x + y;
};
console.log(sum(10, 20)); // 30

/* ES6 */
let sum = (x, y) => x + y;
console.log(sum(10, 20)); // 30;
console.log(typeof sum); // function
console.log(hello instanceof Function); // true /* instanceof operatörü bir objenin belirli bir sınıfa ait olup olmadığını kontrol eder. */


/* ==================================== */


/* ES5 */
let a = 4;
let b = 2;
function (){
return a + b + 10;
} // 16

/* ES6 */
let a = 4;
let b = 2;
() => a + b + 10; // 16


/* ==================================== */


/* ES5 */
let numbers = [4,2,6];
numbers.sort(function(a,b){
return b - a;
});
console.log(numbers); // [6,4,2]

/* ES6 */
let numbers = [4,2,6];
numbers.sort((a,b) => b - a);
console.log(numbers); // [6,4,2]


/* ==================================== */


/* ES5 */
var arr = [1, 2, 3];
var squares = arr.map(function (x) { return x * x }); // [1,4,9]

/* ES6 */
const arr = [1, 2, 3];
const squares = arr.map(x => x * x); // [1,4,9]


/* ==================================== */


/* ES5 */
const kisiler = [{name: 'ali', age: 30}, {name: 'veli', age: 5}, {name: 'ayşe', age: 9}];
const isimler = kisiler.map(function (kisi) {
return kisi.name
});
console.log(isimler); // ["ali", "veli", "ayşe"]

/* ES6 */
const kisiler = [{name: 'ali', age: 30}, {name: 'veli', age: 5}, {name: 'ayşe', age: 9}];
const isimler = kisiler.filter(kisi => kisi.name);
console.log(isimler); // ["ali", "veli", "ayşe"]


/* ==================================== */


/* ES5 */
function Component() {
var _this = this;
var button = document.getElementById('myButton');
button.addEventListener('click', function () {
console.log('CLICK');
_this.handleClick();
});
}
Component.prototype.handleClick = function () { };

/* ES6 */
function Component() {
var button = document.getElementById('myButton');
button.addEventListener('click', () => {
console.log('CLICK');
this.handleClick();
});
}
24 changes: 24 additions & 0 deletions 1.0.3-default_parameters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Default Parameters */

const sum = (a = 10, b = 2) => a+b;
sum (2,2) // 4
sum () // 12
sum (3) // 5


/* ==================================== */


const arr = (x=1,y) => [x,y];
arr() // [1, undefined]
arr(2) // [2, undefined]
arr(2,3) // [2, 3]


/* ==================================== */


const arr = (x,y=1) => [x,y];
arr() // [undefined,1]
arr(3) // [3,1]
arr(3,4) // [3,4]
76 changes: 76 additions & 0 deletions 1.0.4-rest_spread_operators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* REST Operator */

/* ES5 */
function sum(a, b){
return a + b;
}
console.log(sum(1, 2)); // 3
console.log(sum(1, 2, 3, 4, 5)); // 3

/* ES6 */
function sum(...input){
let total = 0;
for (let i of input) total += i;
return total;
}
console.log(sum(1,2)); //3
console.log(sum(1,2,3)); //6
console.log(sum(1,2,3,4,5)); //15


/* ==================================== */


function sum(...numbers){
let total=0; numbers.forEach(el=>total+=el);return total;
}
console.log(sum(2,4,6,5)) // 17


/* ==================================== */


function myFunc(a, b, ...moreArgs) {
console.log("a", a) // one
console.log("b", b) // two
console.log("moreArgs", moreArgs) // three four five six
console.log(moreArgs.length); // 4
}

myFunc("one", "two", "three", "four", "five", "six")


/* SPREAD Operator */

console.log(Math.max(3, 5, 1)); // 5

let arr = [3, 5, 1];
console.log(Math.max(arr)); // NaN
console.log(Math.max(...arr)); // 5


/* ==================================== */


let arr1 = [1, -2, 3, 4];
let arr2 = [8, 3, -8, 1];
console.log(Math.max(...arr1, ...arr2)); // 8
console.log(Math.max(1, ...arr1, 2, ...arr2, 25)); // 25


/* ==================================== */


let str = "Hello";
console.log( [...str] ); // [H,e,l,l,o]


/* ==================================== */

/* ARRAY Copy */

let arr = [1, 2, 3];
let arrCopy = [...arr];
console.log(JSON.stringify(arr) === JSON.stringify(arrCopy)); // true
console.log(arr === arrCopy); // false

Loading