Image for post
Image for post
Photo by Osman Rana on Unsplash


Javascript Default Parameters

Javascript Default Parameters Nasıl Çalışır ? Ne avantaj sağlar ?

Onur Dayıbaşı
Nov 17, 2019 · 3 min read

1. Falsy ve Truthy değerler nelerdir?

if (true)
if ({})
if ({age:12})
if ([])
if ([])
if (42)
if ("0")
if ("false")
if (new Date())
if (-42)
if (12n)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)

2. Type Coercion, Conversion ve Double exclamation points (!!) nelerdir ?

let age=39
let name="Onur"
let user={age:39 name:'Onur'}
let users=[]
let school;
if(age) true
if(name) true
if(user) true
if(users) true
if(school) false
let rslt=!!school //Double exclamation point 2defa -1 carpılır.
console.log(result) //false
5+2.0 //7 burda float değeri implicit olarak int dönüşür.
Number("7") // burda string değeri explicit olarak int dönüşür.

3. Default Parameters Nasıl Çalışır ? Ne Avantaj sağlar ?

//Without Default Parameter
function ekle(arr,val){
if(arr===undefined) arr=[];
return arr;
//With Default Parameter
function ekle(arr=[],val){
return arr;
function sum(a=10, b=2){
return a+b;
sum (2,2) //4
sum () //12
sum (3) //5
function test(num = 1) {
console.log(typeof num);

test(); // 'number' 1
test(undefined); // 'number' 1
test(''); // 'string' ''
test(null); // 'object' null


Frontend Development With JS

Frontend Development With Javascript

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store