0

While practicing the javascript exercises, i was confused to understand why arguments passed for a JS function is not validated with function definition

Example:

function display() {
  console.log('my function');
} 

if i called display(12), code still executes and prints 'my function'.

Same way there are many combinations that will also pass if there are mismatch in arguments vs function parameters

while this type of functional calling don't work in other languages like Java

Ankit
  • 2,126
  • 4
  • 33
  • 53

1 Answers1

0

Its a basic principle of Software Engineering, though not always followed - "Be lenient with what you accept, be strict with what you put out."

In other words, if the function CAN work with what it gets, why would you want it to fail?

MikeB
  • 580
  • 3
  • 18
  • Want to understand how javascript function arguments execution is different from other languages. However, i got more references for more details – Ankit Mar 06 '23 at 10:52
  • 1
    Don't compare JS to other languages, ESPECIALLY Java, just learn how it actually works. – MikeB Mar 07 '23 at 08:32