Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Boolean and boolean in Typescript? [duplicate]

Can someone please explain the difference between Boolean and boolean in Typescript?

like image 1000
Yogesh Nikam Avatar asked Oct 20 '20 10:10

Yogesh Nikam


People also ask

What is difference between Boolean and Boolean in Typescript?

Uppercase Boolean is an object type. Lowercase boolean is a primitive type. You should always use boolean (the primitive type in your programs). This is because, the Typescript type system does not force an object to its primitive type, while JavaScript does.

What is difference between Boolean and Boolean?

boolean is a primitive and Boolean is as object wrapper. So boolean, is the type whose values are either true or false while the other is an object. If you wanted to convert a string to a boolean you could try Boolean.

Should you use Boolean or Boolean?

It is recommended that you use the Boolean() function to convert a value of a different type to a Boolean type, but you should never use the Boolean as a wrapper object of a primitive boolean value.

What is Boolean in Typescript?

The boolean is a primitive type in Typescript. It represents a simple true/false value. They are implemented as numerical values with a single binary digit (i.e., 0 & 1). The Boolean is an object wrapper for the primitive boolean value.


1 Answers

Uppercase Boolean is an object type.

Lowercase boolean is a primitive type.

You should always use boolean (the primitive type in your programs). This is because, the Typescript type system does not force an object to its primitive type, while JavaScript does.

You shouldn't write:

function yourFunction(foo: Boolean)

But instead always write:

function yourFunction(foo: boolean)

For more info, see TypeScript Lang - Everyday Types

like image 154
Joel Avatar answered Oct 11 '22 04:10

Joel