I have a JavaScript code which works fine, but I have a question, what does the underscore mean?:
$(document).on('keyup', ".uppercase", function () {
$(this).val(function (_, val) {
return val.toUpperCase();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="uppercase">
What the code does is convert the text written in a input
to uppercase, but inside the code there is an underscore:
$(this).val(function (_, val) {
I would like to know what the script means or what it does.
In this case the underscore
_
is being used as a variable name, you can replace it with a letter and you will see that the function continues to do its job perfectly.https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Grammar_and_types#Variables
Example changing
_
byx
Edit to add Bryro recommendation
We programmers often use it
_
simply as a skip variable; since it will not be useful or its use is not very relevant and it is not necessary to give it a great reference or a descriptive name