<html> <body> <input id="billinput" type="number" placeholder="0" /> <script> const billInput = document.getElementById('billinput'); function cat() { let billInputValue = billInput.value; console.log(billInputValue); } cat(); </script> </body> </html>
Answer: use value instead of placeholder, also you can add optional button to call the function
<html>
<body>
<input id="billinput" type="number" value="0" />
<input type="button" value="Click" onclick="cat()">
<script>
const billInput = document.getElementById('billinput');
function cat() {
let billInputValue = billInput.value;
console.log(billInputValue);
}
cat();
</script>
</body>
</html>