forked from engindemirog/javaScriptStarterKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
93 lines (72 loc) · 2.46 KB
/
function.js
File metadata and controls
93 lines (72 loc) · 2.46 KB
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
//npm run dev localhost açma
function addToCart(product,quantity=10) {//burada quantity default
console.log(product + " added to cart."+ " Quantity : "+ quantity)
}
function removeFromCart(product="Personal Cart"){//burdaki default değerdir
//default değer eğer bir değer göderilezse default değer kullanılır.
console.log(product + " removed from cart")
}
addToCart("Smartphone",15)
addToCart()
let sayHello = () => {
console.log("Hello")
}
sayHello()
function addToCart2(productName,quantity,unitPrice) {
console.log(productName+" "+ quantity+ " "+ unitPrice)
}
addToCart2("elma",10,5);//object olmadan el ile girilmiş hal
function addToCart3(product){
console.log(product.productName+" "+ product.quantity+" "+ product.unitPrice)
}
let product1 = {productName:"Elma",unitPrice:10,quantity:5}//object notation
let product2 = {productName:"Karpuz",unitPrice:10,quantity:5}//object notation
let product3 = {productName:"Armut",unitPrice:10,quantity:5}//object notation
product2 = product3
product2.productName="Elma"
console.log(product3.productName)//reference type -> objectler , array
let say1=10
let say2=20
say1 = say2
say2 = 100
console.log(say1)//value type
addToCart3(product1)//object oluşturulmuş hali
function addToCart4(x ){
console.log(products)//scoup: Süslü parantez bölümü, eğer ilk scroup da yoksa bi üste bakıyor orda olduğu için çalışıyor.
}
let products = [
{productName:"Elma",unitPrice:10,quantity:5},
{productName:"Karpuz",unitPrice:10,quantity:5},
{productName:"Armut",unitPrice:10,quantity:5}
]
addToCart4(products)
function add(...numbers)//rest operatörü(array yapıyor),her zaman sondaki parametre olur
{
let sum=0;
for (let i = 0; i < numbers.length; i++){
sum += numbers[i]
}
console.log(sum)
}
add(20,50,40)
//spread: bir dizinin elemanlarını ayırmak için kullanılır.
let numbers = [1,2,3,4,5,6,7,15]
console.log(...numbers)
//destruck: çoklu atama , set etme
let [icAnadolu, marmara,karadeniz,[icAnadoluSehir,marmaraSehir,karadenizSehir]] = [
{name: "Ic Anadolu", population:"20m"},
{name: "Marmara", population:"30m"},
{name: "Karadeniz", population:"10m"},
[
["Ankara","Konya"],
["Istanbul","Bursa"],
["Karabuk","Trabzon"]
]
]
console.log(icAnadolu)
console.log(marmara)
console.log(icAnadolu.name)
console.log(marmara.name)
console.log(icAnadoluSehir)
console.log(marmara.nameSehir)
console.log(karadenizSehir)