0

Just a simple .js file in one of my drive which contains code

var x=3;
function numSqaure(x)
{
    return(x*x);
}
var sentence="The square of" + x + "is" + numSqaure(x);
console.log(sentence);

I'm trying to run it through Powershell but it shows an error 'console' is undefined .

How to handle this error? I want it through Powershell only.

rashmi1705
  • 35
  • 1
  • 5

1 Answers1

1

Javascript files are made for being executed by a browser, not directly in console unless you're using Node.js or something similar.

Create an HTML with a script tag like this:

<script src="c:\whatever\folder\you\choose\yourscript.js"></script>

and enter developer tools in browser. There this error won't happen anymore and console will exist.

Nelson Teixeira
  • 6,297
  • 5
  • 36
  • 73