1

I want to store and print a variable (string in this case) sent from ejs by console.log in script tag

but it gives me an "(index):19 Uncaught ReferenceError: Cannot access 'text' before initialization"

code in node js

app.get("/", (req, res)=> {
    res.render("index", {message: "hello world"})
})

code in html

<script>
   const text = <% message %>
   console.log("message is " + text);
</script>
JoOoBa1000
  • 33
  • 4
  • 1
    Does this answer your question? [Pass variables to JavaScript in ExpressJS](https://stackoverflow.com/questions/16098397/pass-variables-to-javascript-in-expressjs) – traynor Mar 02 '23 at 18:52

0 Answers0