syntax meaning of ' (method) alert(message?: any): void ' in 'window.alert()' in javascript?

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)?

92 thoughts on “syntax meaning of ' (method) alert(message?: any): void ' in 'window.alert()' in javascript?”

  1. The closest Java equivalent would be

    public void alert(Optional<Object> message){...}
    

    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:

    • alert() — No message argument
    • alert("hello") — One argument

    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.

    Reply
  2. alert(message?: any): void;

    alert() : it is a method

    message?: any => message is parameter which goes to alert method, ? mark suggest it is optional

    void => its a return type of that method

    Reply

Leave a Comment