As I wrote in the title, I'd like to get a value from a variable written into a ejs page/file, from a javascript file within the same page
EJS:
<% var test = 101; %>
JS:
<script>
var getTest = test;
</script>
Or what if I'd like to use a function (with parameter) written into a EJS file and use this function in a JS context where the parameter is given to the function from JS context
EJS:
<% function fn(par){ ... } %>
JS:
<script>
var test = 101;
<%>fn(test)<%>
</script>
Edit: this Half considers you are using EJS on server side
simply create an ejs variable and assign the value inside the script tag to the
var getTest
Ex:
var getTest = <%= test %>;
Yes, you cant: if it is on server.
Why:
The EJS template will be rendered on the server before the Javscript is started execution(it will start on browser), so there is no way going back to server and ask for some previous changes on the page which is already sent to the browser.
Edit: this Half considers you are using EJS on Client side
The answer above will still work, but you will require to load the script within the EJS template, not the script loaded before the template rendered(in that case it will of-course no be a valid javascript).
I m sorry I have myself not tried this case, but I really look forward if someone answers this case