In Visual Studio Code
, while making a react app when I move my cursor on window.alert()
, I see a pop up which reads as follows:
alert(message?: any): void;
(method) alert(message?: any): void
Please explain what it means, as I am from java background and I can’t understand it. I could only understand that alert()
is a method which returns nothing, but what about it’s parameters?
What is (message?: any)
?
The closest Java equivalent would be
java.lang.Object
cannot extend primitive types, however, Javascript can.In the javascript, the delimiter
?
means the parameter is optional.For example, both of these are acceptable:
Additionally type
any
denotes the value can by any Object Type, including primitive types. For example it can be a boolean, string, or number, or any Class types such as React, Button, or JSXElement.alert(message?: any): void;
alert()
: it is a methodmessage?: any =>
message is parameter which goes to alert method, ? mark suggest it is optionalvoid =>
its a return type of that method