How can val() return Number? How can val() return Number? jquery jquery

How can val() return Number?


A text input's value attribute will always return a string. You need to parseInt the value to get an integer:

parseInt($('#myInput').val(), 10);


Some HTML5 elements e.g. progress;

console.log(typeof $("#prog").val()); // number 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><progress value="50" max="100" id="prog"></progress>