Is there a Java Scanner equivalent in Javascript?

Asked

Viewed 823 times

2

For now I’m just messing with Javascript in the terminal. Is there any method in Javascript that has a function similar to Scanner that exists in Java.

  • How is the code running in the ? terminal with Node ?

1 answer

2


Does not exist in the implementation of browsers. They are languages that implement these things in libraries and not in the language itself. Java is used primarily as a backend, console and GUI (less), so it makes sense to have a function that asks for data from the console. Javascript is usually used in web browsers and it doesn’t make sense to have something like this, but there might be something that does a similar task (on Node or other implementation it might make sense to have something like this running on console, see readline()).

In Javascript has the prompt(), that cannot be considered equivalent, only similar, even because Java tries to evaluate the type of data entered and in JS this is not done, it is the programmer’s problem to evaluate if the data entry is within what is expected in basic format of the given type (there are functions that help). Java is a static typing language and this is important, in JS not.

Has something for the purpose of purification, but I don’t know if it’s universally available.

The most common is to use HTML to request an input information, usually with a tag <input "text">. Then you will have to use JS to take the data typed there and do what you want (several examples by the site here and documentation of one of the functions).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.