How pass string to $w(..)?

You should be doing something like this:

$w(`#${str}`);

See the article on template literals for more information.

You should also be able to do something like this:

$w('#' + str);

Don’t forget to put the # in quotes.