Why .js file created in doctypes what it does? what is use of that .js file?

why .js file created in doctypes what it does? what is use of that .js file?

You can add triggers for form events. See example: https://github.com/frappe/frappe/blob/develop/frappe/core/doctype/event/event.js