You guys have heard of closures in javascript ?!
it's very simple and straightforward just compare you current input value with the old value that the setTimeOut function closes over, and voila, you're done.
let timer;
$('#myInput').on('keyup', function() {
window.clearTimeout(timer);
// here is the closures javascript magic happens.
const value = $(this).val();
timer = setTimeout(() => {
if(value === $(this).val() && $(this).val()!== ''){
alert($(this).val());
}
}, 500);
})