Jump to content

JScript .NET: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Line 35: Line 35:


=== Differences with C++ ===
=== Differences with C++ ===
* JScript .NET does not require a [[Main function (programming)|main()]] function.
* JScript .NET does not require a [[Main function (programming)|main()]] [[Function|function]].


* JScript .NET does not require explicit [[type declaration]] on variables. (In [[C_Plus_Plus|C++]], the use of templates and generics can be compared to this, loosely emulated with template specialization etc)
* JScript .NET does not require explicit [[type declaration]] on variables. (In [[C_Plus_Plus|C++]], the use of templates and generics can be compared to this, loosely emulated with template specialization etc)

Revision as of 06:23, 6 September 2005

JScript .NET is a .NET programming language developed by Microsoft as a natural successor to Microsoft's Active Scripting language JScript.

Both JScript and JScript .NET are languages whose syntax is based on that of C language. JScript has no relation to Sun Microsystems' Java language (see this section of JavaScript article for discussion on the confusing naming) The primary differences between JScript and JScript .NET can be summarized as follows:

The original JScript is a scripting language, and as such program (or more suggestively, scripts) can be executed without the need to compile the code first. This is not the case with JScript .NET, since this next-generation version relies on the .NET CLR (Common Language Runtime) for execution, which requires that the code be compiled to MSIL (Microsoft Intermediate Language) code before it can be run.

Secondly, the original JScript had a strong foundation in Microsoft's ActiveX/COM technologies, and relied primarily on ActiveX components to provide much of its functionality (including database access via ADO, file handling etc.), whereas JScript .NET uses the .NET Framework to provide equivalent functionality.

Although the .NET Framework and .NET languages such as C# and Visual Basic .NET have seen widespread adoption, JScript .NET has never received much attention, by the media or by developers. It is not supported in Microsoft's premier development tool, Visual Studio .NET, and it's unlikely that future versions of .NET will feature JScript .NET prominently.

But ASP.NET supports JScript .NET.

Language Differences

The following are prime examples of languages differences between other .NET Languages, including comparisons.

Differences with C#

  • JScript variables do not need to be declared as a certain type. For example, the following code will cause a compiling error in other languages, but not in JScript .NET:
var i = 0; 
var s = "hello";
  • JScript .NET does not have a main() function that the operating system must call directly when executing a JScript .NET application, as such, JScript .NET program flow is based entirely on global code.
  • JScript .NET, because of its very loose type checking system can be very easy to learn, since the convention of explicit type declaration is not required at all.
  • JScript .NET does not require explicit references to the .NET Framework Base Class Library, as certain functions found in earlier versions of JScript, are present in JScript .NET (e.g. functions for finding the tangent of an angle for a right triangle).
  • JScript .NET is closely linked to C syntax, and is thus very easy to learn for C#, Java or C++ developers.
  • While JScript .NET can be used to create Windows Forms applications, JScript .NET will have some trouble, as delegates can only be consumed in JScript .NET and not created. Thus, custom events are hard to emulate in JScript .NET.

Differences with C++

  • JScript .NET does not require explicit type declaration on variables. (In C++, the use of templates and generics can be compared to this, loosely emulated with template specialization etc)
  • JScript .NET also does not require explicit type casts on variable use in the program. Code used to retrieve a string of characters, but only used for integer numbers can be casted implicitly; the vice-versa can be done without error at compile time, but there is a chance of loss of precision or data.

e.g.:

import System;

var _name;

Console.WriteLine("Hello, what's your name?");
Console.WriteLine("Type your name: ");

var _name = Console.ReadLine();
//provide a number and it will output it below, without error

Console.WriteLine("Hello, " + _name);

Differences with Java

  • JScript .NET syntax and lexical conventions are similar to Java in that both are derived from C. JScript was originally Microsoft's implementation of ECMAScript, which is more commonly known as JavaScript, though unrelated to Java. Thus, users of Java and other C-derived languages will find JScript easier to learn.
  • JScript .NET allows developers to use untyped variables, and can sometimes infer their type from their usage to optimize the compiled code. On the other hand, Java requires all variables to be typed.
  • JScript .NET can add properties and methods to objects in run-time, while Java objects always conform to their declared interface.
  • JScript .NET applications, unlike Java, (while still is a scripting language) are not interpreted. They are compiled and executed, running without the overhead of an interpreter (but still with a garbage collector).

Differences with older versions of JScript

  • JScript .NET allows developers to declare typed variables and functions, while JScript can only declare variables and functions of the 'universal type'.
  • JScript .NET scripts are not interpreted, but executed independently. When executed, a JScript .NET application will invoke the CLR and garbage collector and the CLR will execute the MSIL instructions, but CLR will not interpret directly, the MSIL instructions.
  • JScript .NET can be run without the presence of a browser or another scripting engine.
  • JScript .NET provides access to the .NET Framework BCL (Base Class Library), providing much more functionality.
  • JScript .NET, like older versions of JScript, provide in built functions to keep common functions simple.
  • JScript .NET is only supported on the server side (in only one case: ASP.NET), thus JScript .NET cannot be run inside the browser or such as older JScript versions do, which makes it [older versions of JScript] much more versatile.

References