Number türünü String yapmak
   let num = 16;
   
   console.log(typeof num); // number
   
   num = 16 + “”;
   
   console.log(typeof num); // string
  
| 
      
 let num = 16 ; console . log ( typeof num ) ; // number 
 num = 16 + “” ; console . log ( typeof num ) ; // string 
  | 
   
   
   ES6 ile gelen fonksiyon için varsayılan olarak değer atama
  
   function foo(a=10, b=15, c=20) {
   
   console.log(a,b,c);
   
   }
   
   foo(); //10, 15, 20
  
| 
      
 function foo ( a = 10 , b = 15 , c = 20 ) { console . log ( a , b , c ) ; } 
 foo ( ) ; //10, 15, 20 
  | 
   
   
   Diziyi verdiğimiz sayı kadar doldurma
  
   //  Array Fills
   
   const myVar = Array(5).fill(“”);
   
   console.log(myVar); // [“”, “”, “”, “”, “”]
  
| 
      
 // Array Fills const myVar = Array ( 5 ) . fill ( “” ) ; console . log ( myVar ) ; // [“”, “”, “”, “”, “”] 
  | 
   
   
   Dizilerde aynı olan değerleri bir kez alma
  
   const users = [“John”, “Mark”, “Anna”, “Bob”,”Mark”,”Bob”,”Mark”];
   
   // Set her değerin sadece birer kez olabileceği yapılardır
   
   const unique = Array.from(new Set(users));
   
   console.log(unique);  // [“John”, “Mark”, “Anna”, “Bob”]
  
| 
      
 const users = [ “John” , “Mark” , “Anna” , “Bob” , “Mark” , “Bob” , “Mark” ] ; 
 // Set her değerin sadece birer kez olabileceği yapılardır const unique = Array . from ( new Set ( users ) ) ; 
 console . log ( unique ) ; // [“John”, “Mark”, “Anna”, “Bob”] 
  | 
   
   
   ES6 ile birlikte, daha önce tanımladığımız değişkeni aşağıdaki örnekteki gibi köşeli parantezler içerisine alarak nesne içerisinde dinamik olacak şekilde kullanabiliyoruz.
  
   //Dynamic Objects
   
   const dynamic = “email”;
   
   const user = {
   
   name : ‘John’,
   
   lastname : ‘Doe’,
   
   [dynamic] : ‘[email protected]’,
   
   };
   
   console.log(user);
   
   // {
   
   //   name: “John”,
   
   //   lastname: “Doe”,
   
   //   email: “[email protected]”
   
   // }
  
| 
      1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  | 
    
      
 //Dynamic Objects const dynamic = “email” ; 
 const user = { name : ‘John’ , lastname : ‘Doe’ , [ dynamic ] : ‘[email protected]’ , } ; 
 console . log ( user ) ; 
 // { // name: “John”, // lastname: “Doe”, // email: “[email protected]” // } 
  | 
   
   
   Dizileri belli bir değerde kesme
  
   // Slicing Arrays
   
   const cars = [“Saab”, “Volvo”, “BMW”, “Opel”, “Skoda”, “Seat”];
   
   cars.length = 3;
   
   console.log(cars); // [“Saab”, “Volvo”, “BMW”]
  
| 
      
 // Slicing Arrays const cars = [ “Saab” , “Volvo” , “BMW” , “Opel” , “Skoda” , “Seat” ] ; cars . length = 3 ; 
 console . log ( cars ) ; // [“Saab”, “Volvo”, “BMW”] 
  | 
   
   
   Dizilerdeki son değeri alma
  
   // Slicing Arrays End
   
   const myNumbers = [1 ,2 ,3 ,4 ,5 ,6, 7];
   
   console.log(myNumbers.slice(-1));  // [7]
   
   // ya da
   
   // Son 3 Değer
   
   console.log(myNumbers.slice(-3));  // [5, 6, 7]
  
| 
      
 // Slicing Arrays End const myNumbers = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; console . log ( myNumbers . slice ( – 1 ) ) ; // [7] 
 // ya da 
 // Son 3 Değer console . log ( myNumbers . slice ( – 3 ) ) ; // [5, 6, 7] 
  | 
   
   
   Diziyi Objeye çevirme
  
   //Array to Object
   
   const fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
   
   const fruitsObject = { …fruits };
   
   console.log(fruitsObject);
   
   // {
   
   //   0: “Banana”,
   
   //   1: “Orange”,
   
   //   2: “Apple”,
   
   //   3: “Mango”
   
   // }
  
| 
      
 //Array to Object const fruits = [ “Banana” , “Orange” , “Apple” , “Mango” ] ; const fruitsObject = { . . . fruits } ; 
 console . log ( fruitsObject ) ; 
 // { // 0: “Banana”, // 1: “Orange”, // 2: “Apple”, // 3: “Mango” // } 
  | 
   
   
   Objeyi Diziye Çevirme
  
   //Object to Array
   
   const person = {
   
   name : ‘John’,
   
   lastname : ‘Doe’,
   
   email : ‘[email protected]’,
   
   };
   
   const personArray = Object.values(person);
   
   console.log(personArray);  // [“John”, “Doe”, “[email protected]”]
  
| 
      
 //Object to Array const person = { name : ‘John’ , lastname : ‘Doe’ , email : ‘[email protected]’ , } ; 
 const personArray = Object . values ( person ) ; 
 console . log ( personArray ) ; // [“John”, “Doe”, “[email protected]”] 
  | 
   
   
   If koşulunun kısa kullanımı
  
   let hungry = “Açım”;
   
   function goToFridge() {
   
   console.log(“O zaman yemek vakti”);
   
   }
   
   if (hungry) {
   
   goToFridge();
   
   }
   
   // ya da
   
   hungry && goToFridge()
   
   // Çıktı: O zaman yemek vakti
  
| 
      1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  | 
    
      
 let hungry = “Açım” ; 
 function goToFridge ( ) { console . log ( “O zaman yemek vakti” ) ; } 
 if ( hungry ) { goToFridge ( ) ; } 
 // ya da 
 hungry && goToFridge ( ) 
 // Çıktı: O zaman yemek vakti 
  | 
   
   
   Bazı beklenmedik durumlarda değişkenlerin tanımsız kalmaması için
   
    OR
   
   operatörünün kullanılması
  
   function doSomething(arg){
   
   arg = arg || 20; // arg değişkeni önceden ayarlanmamışsa değeri 20 olacaktır.
   
   console.log(arg);
   
   }
   
   doSomething();
   
   // Çıktı: 20
  
| 
      
 function doSomething ( arg ) { arg = arg || 20 ; // arg değişkeni önceden ayarlanmamışsa değeri 20 olacaktır. console . log ( arg ) ; } 
 doSomething ( ) ; 
 // Çıktı: 20 
  | 
   
   
   Bu yazının devamı niteliğinde olan
   
    JavaScript’te kod yazarken zaman kazandıracak bazı yöntemler
   
   başlıklı yazıya
   
    buradan
   
   ulaşabilirsiniz.