Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing single argument into a function that requires multiple arguments in javascript

Tags:

javascript

I'm trying to read through some source code on the internet, and I'm getting confused because the author defined a function as:

var _0x80a1 = function (x, a) {...}

But then only calls it using statements like this:

_0x80a1("0x0")

How does that work?

like image 284
iggy12345 Avatar asked Jan 24 '26 11:01

iggy12345


1 Answers

JavaScript parameters are optional you don't need to pass them. So you can do something like this:

function multiply(a, b) {
  if(typeof b === 'undefined') { 
    b = 10;
  }
  return a * b;
}

console.log(multiply(5));
// expected output: 50

In newer versions of JS you can also do default parameters like this:

function multiply(a, b = 10) {
  return a * b;
}

console.log(multiply(5));
// expected output: 50
like image 91
otw Avatar answered Jan 27 '26 01:01

otw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!