In the following two style of writing code,
<script>
function foo() {
// do something;
}
</script>
<script>
const foo = function() {
// do something;
}
</script>
Is the second way preferred over the first and is there any practical reason?
My "feeling" is that the second way is more modern and is seen more often these days, but couldn't explain why it is actually better.