How best to determine if an argument is not sent to the JavaScript function

I have now seen 2 methods for determining if an argument has been passed to a JavaScript function. I’m wondering if one method is better than the other or if one is just bad to use? function Test(argument1, argument2) { if (Test.arguments.length == 1) argument2 = ‘blah’; alert(argument2); } Test(‘test’); Or function Test(argument1, argument2) { … Read more

Meaning of “[: too many arguments” error from if [] (square brackets)

I couldn’t find any one simple straightforward resource spelling out the meaning of and fix for the following BASH shell error, so I’m posting what I found after researching it. The error: -bash: [: too many arguments Google-friendly version: bash open square bracket colon too many arguments. Context: an if condition in single square brackets … Read more

Converting an array to a function arguments list [duplicate]

This question already has answers here: Passing an array as a function parameter in JavaScript (12 answers) Closed 5 years ago. Is it possible to convert an array in JavaScript into a function argument sequence? Example: run({ “render”: [ 10, 20, 200, 200 ] }); function run(calls) { var app = …. // app is … Read more

if arguments is equal to this string, define a variable like this string

I am doing some bash script and now I got one variable call source and one array called samples, like this: source=”country” samples=(US Canada Mexico…) as I want to expand the number of sources (and each source has its own samples) I tried to add some arguments to do this. I tried this: source=”” samples=(“”) … Read more

Setting default value for TypeScript object passed as argument

function sayName(params: {firstName: string; lastName?: string}) { params.lastName = params.lastName || ‘smith’; // <<– any better alternative to this? var name = params.firstName + params.lastName alert(name); } sayName({firstName: ‘bob’}); I had imagined something like this might work: function sayName(params: {firstName: string; lastName: string = ‘smith’}) { Obviously if these were plain arguments you could do … Read more