ES6 adds default and rest parameters to your functions. Default parameters can replace the old method of having to check whether arguments were passed in, then assigning them if they're missing:
var production = true;
// By default, use log. Before we'd have to check argument.length
// or whether type was undefined to get the same effect:
function DEV_LOG(string, type = "log")
{
if (!production || type === "error")
console[type](string);
}
// Won't print since in production.
DEV_LOG("Status Log");
// Will print since its an error.
DEV_LOG("Error Log", "error");
With rest parameters, you can easily treat multiple parameters as if they were part of a list:
Spread allows you to do the opposite. Many functions expect all the items to be given as parameters, not one big list (such as Math.max). Spread allows us to "unwind" a list into parameters:
var numbers = [1,2,3,4,5,6,7,8,9,10];
Math.max(...numbers);
Loading…
28 comments
posted a year ago by 65374c7ea7ec220008a7bdfb
I
posted a year ago by elmonjo
I want to go lovely
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
1
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
1
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
-1 OR 2+820-820-1=0+0+0+1 --
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
-1 OR 2+827-827-1=0+0+0+1
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
-1' OR 2+194-194-1=0+0+0+1 --
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
-1' OR 2+421-421-1=0+0+0+1 or 'Ica3fizv'='
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
-1" OR 2+173-173-1=0+0+0+1 --
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
1*if(now()=sysdate(),sleep(15),0)
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
10'XOR(1*if(now()=sysdate(),sleep(15),0))XOR'Z
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98
10"XOR(1*if(now()=sysdate(),sleep(15),0))XOR"Z
posted 4 months ago by 396abf98bfbf9e0278c0ff5763ab8d98