Skip to content
Advertisement

Javascript: template literals not returning ${} syntax output [closed]

I am watching a YouTube video about learning javascript from some years ago, and in the video the code seems to work except on my VScode.

Here is the code, could you please let me know what I might have missed out:

function Person(firstName, lastName, dob) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.dob = new Date(dob);
    this.dateBio = function() {
        return `${this.dob.getFullYear}`
    }

}

Person.prototype.fullName = function() {
    return `${this.firstName} ${this.lastName}`
}

const person1 = new Person('James','Smith', '27 July 1967');
const person2 = new Person('Mary', 'Franklin', '5 November 1991')

console.log(person1.fullName)

Advertisement

Answer

you have logged function reference only, you need to call the function.

console.log(person1.fullName())
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement