Just finished reading an enlightening article on the FreeCodeCamp website all about the intricacies of the this
keyword in JavaScript. I decided to test out some of the code snippets provided, but surprisingly enough, I ended up with completely different results.
function alerty() {
console.log(this.named + ' is calling');
}
const named = 'Kingsley';
alerty(); // Kingsley is calling'
alerty()
seems to be displaying"undefined is calling
" instead of the expected output of"Kingsley is calling"
as outlined in the article.- I made sure not to include
'use strict';
in my code at any point. - What could possibly be causing this unexpected behavior?