Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How execute JS

Status
Not open for further replies.

jimoo

Programmer
Jun 2, 2003
1,111
US
I am have a basic understand of JS and I have worked with VB Script quite a bit so I am familiar with scripting languages.

I have decided to explore my knowledge of JS further. Of course, there are lots of examples and articles.

The basic question I have is what is the best way for me to create and execute JS code from a Windows PC? At this point I am just looking to do simple things like define and assign variables and arrays and then iterate though them and display the values and latter progress to IF/ESLE & CASE as well as response text boxes.

Any tips for getting started?

Jim
 
There is no best way to create a script on a PC. Some will use fancy editors like Visual Studio Code, some will just use notepad. If you are still using office 2000, it contains the Microsoft Script Editor, which was brill as a js or vbs IDE. Unfortunately, MS withdrew it from office 2003 onwards citing it was hardly used. Pretty lame reason - if you don't tell anyone it is there, of course nobody will use it.

Executing the code is the same as VBS

cscript xxx.js

Like VBS, if you have echo statements and you use

wscript xxx.js

all the echo statements will appear as message boxes which you have to OK.

It has some features which are similar to vbs - js is JScript: not really Javascript. It is case sensitive on some bits but not on others. For instance,
Code:
wscript.echo("Does not work - wscript undefined")
WScript.echo("This works")
WScript.Echo("As does this")
WScript.ECHO("And this")

One of the problems with jscript and javascript examples is many of the coders love using nameless functions. Very often, you need to take the code apart to figure out what is happening. Unless you can work out what the nameless functions are doing, it can get very difficult to decipher the code. Instead of

Code:
function add(x,y) {
    return x + y
}
z = add(20, 25)

they would rather write

Code:
z = function (x, y) {
    return x + y
}(20,25)

The authors don't normally comment their nameless function code so you may have a nice time trying to figure out what it is doing. Think very hard about "will I understand this when looking at it in a year's time" before you go down the nameless function route.

You can embed your code in a WSF file. This will allow you to have both js and vbs bodies. You can execute either or both. Great for translation which allows you to run both scripts.

One of the advantages of js is it is a transferable skill. You can write customised code in Office 365, Google Apps Script (GAS) and web code.
 
Thanks for the response. I am hoping to find lightweight IDE. I have used .NET in the past but don't currently have it installed and would prefer not to unless I have to. I did a google search and found a few but don't know the difference between a good one and a bad one.

Temporarily, I have been using HTML but I am looking for something better.

Example:

<html>
<head>
<title>Test Program</title>
</head>

<body>
<script language = "javascript" type = "text/javascript">
document.write("Hello World!")
</script>
</body>
</html>

Jim
 
You could try

[ul]
[li]Visual Studio Code - quite light weight with a lot of the Visual Studio goodies thrown in. This can cope with the mix of html and jscript/vbscript and you can set breakpoints[/li]
[li]Geany - takes a while to start. This is basically a multi-language editor like VSCode. I've never used it for debugging.[/li]
[li]Codelobster - started life a a php editor and evolved from there.[/li]
[/ul]

All 3 are used by both Windows and Linux users so there is quite a lot of help out there if you ever get stuck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top