Variable declared but never read

When I mouse over this variable in Visual Studio Code I see that "this variable is declared but never read and it is grayed out.

When I use it like this I get an error "cant read properties of undefined first_name

const more_data = document.getElementById("more_data");
more_data.innerHTML = "<p>test</p>" .myData_2.first_name;

But when I use it like this I don’t get error

const more_data = document.getElementById("more_data");
more_data.innerHTML = myData_2.first_name;

I would like to put some plain text before that variable if possible.

Thanks

In JavaScript you are CONCAT strings with + sign not with . Like in PHP

2 Likes

Thank you :slight_smile:

@Stribor45

You can also use a template string (`${backticks}`)

e.g.

const moreData = document.getElementById("more_data");

moreData.innerHTML = `<p>test</p>${myData_2.first_name}`;

It’s also more common to use camelCase in JS rather than snake_case.

2 Likes