Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print arguments' list in javascript?

Tags:

javascript

Is there a way to print arguments' list in full or in parts in JavaScript?

Example: from within the function my_assert(a!=b) I'd like to print a!=b, or even 2!=3 for a particular function call.

like image 408
BreakPhreak Avatar asked Sep 13 '11 07:09

BreakPhreak


People also ask

What is an argument list in JavaScript?

arguments is an Array -like object accessible inside functions that contains the values of the arguments passed to that function.

How do you access arguments in JavaScript?

It's a native JavaScript object. You can access specific arguments by calling their index. var add = function (num1, num2) { // returns the value of `num1` console. log(arguments[0]); // returns the value of `num2` console.

How do you find the number of arguments in a function?

Syntax *args allow us to pass a variable number of arguments to a function. We will use len() function or method in *args in order to count the number of arguments of the function in python.

How can you get the type of arguments passed to a function in JavaScript Mcq?

Using typeof operator, we can get the type of arguments passed to a function.


2 Answers

you can't. a!=b is executed first and only the result of this (true or false) is given to your function so you don't have a chance to get back a!=b or 2!=3.

like image 66
oezi Avatar answered Oct 14 '22 01:10

oezi


 console.log (arguments)

will print the arguments given to the function, but in your case, all your function sees is a boolean, because a != b will be evaluated first, and only the result passed as a parameter in the function call.

like image 31
Thilo Avatar answered Oct 14 '22 00:10

Thilo