Search code examples
javascriptalertquotesdouble-quotes

How do I show single and double quotes in a text alert in javascript?


I want a javascript alert that reads, "It's "Hammer" time!"

What is the best code to write this?


Solution

  • Although you could use a string with ' and escape the ', or a string with " and escape the "s, it would be better to use a template literal, which doesn't require escaping of quotes because its delimiter is the backtick:

    alert(`"It's "Hammer" time!"`);