Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functions are true values?

I've just started reading JavaScript: The Definitive Guide and I don't understand what the author means when he says:

"The most important thing about functions in JavaScript is that they are true values and that JavaScript programs can treat them like regular objects."

What does he mean that they are "true values"? And why does this mean that they can be treated like objects?

like image 249
LaughingMan Avatar asked Nov 25 '15 15:11

LaughingMan


People also ask

Which function is true?

The TRUE Function[1] is categorized under Excel Logical functions. It will return the logical value of TRUE. The function is equivalent to using the Boolean value TRUE directly in a formula. In financial analysis, the TRUE function is often used with other logical functions such as IF, ERROR, etc.

What is true function in Excel?

You can also enter the value TRUE directly into cells and formulas without using this function. For example: =IF(A1=1,TRUE) If the condition is met, Excel returns TRUE in both examples. If the condition is not met, Excel returns FALSE in both examples.

How do you make a function True or false?

The TRUE and FALSE functions There are TRUE and FALSE functions in Excel as well. For instance, if you type “=TRUE()” into a cell, it will return the value TRUE. If you type “=FALSE()” it will return FALSE.

Which function is check true or not?

The IF function checks whether a condition is met, and returns one value if true and another value if false.


1 Answers

It means JavaScript does not make a distinction between functions or strings, or numbers or booleans, as far as it is concerned they're all the same.

They're all objects.

Objects are key/value pairs in JS, just like

"neilmunro".length;

Will be 9.

function sayHi() { console.log("Hi"); }
sayHi.name;

Will print out "sayHi".

Functions can be passed to other functions:

function doSomething(name, func) {
    console.log("Hi: " + name);
    func();
}

doSomething("Neil", function() { console.log("You're a human!"); });

It's a bit mind bending, and there's a lot more to it than just that, but it's the basic idea.

like image 50
Neil Munro Avatar answered Oct 13 '22 00:10

Neil Munro