How to create user defined constants in JScript?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2010
02:12 AM
04-05-2010
02:12 AM
How to create user defined constants in JScript?
Hello,
I wanted to know how to create user defined constants in JScript. The help in the Code Metrics sugests to use constants for magic numbers, etc. Are these "constants" just variables defined at the beginning of the script? Or there is some king of special "const" keyword?
Thank you,
Patricio.
I wanted to know how to create user defined constants in JScript. The help in the Code Metrics sugests to use constants for magic numbers, etc. Are these "constants" just variables defined at the beginning of the script? Or there is some king of special "const" keyword?
Thank you,
Patricio.
5 REPLIES 5
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2010
01:04 AM
04-06-2010
01:04 AM
Hi
I suggest that you see the "Declaring JScript Variables and Constants" and "User Defined Data Types" MSDN articles.
-----
Alexander
Customer Care Manager
Alexander
Customer Care Manager
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2010
01:27 AM
04-06-2010
01:27 AM
Hello Alex,
Yes, I found those links before. The only form that does not gives a syntax error in TestComplete is "var <name> = <value>;". All the rest gives you a syntaxt error while processing "const":
const daysInWeek = 7;
const favoriteDay = "Friday";
const daysInWeek : int = 7;
Regards,
Patricio.
Yes, I found those links before. The only form that does not gives a syntax error in TestComplete is "var <name> = <value>;". All the rest gives you a syntaxt error while processing "const":
const daysInWeek = 7;
const favoriteDay = "Friday";
const daysInWeek : int = 7;
Regards,
Patricio.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2010
06:07 PM
04-06-2010
06:07 PM
Hi Patricio,
Sorry for the confusion. The articles I gave you are regarding JScript .NET. The scripting language used in TestComplete is not a .NET version. In regular JScript, constants are not supported, so the "const" statement is not available.
I suggest that you use variables instead. Please see the "About Variables" and the "Code Metrics" articles for the information.
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2010
06:32 AM
04-09-2010
06:32 AM
To minimize your global namespace, I suggest you create constants under an object literal:
var Constants = {
A : 1,
B : 2,
C : 3
};
var Constants = {
A : 1,
B : 2,
C : 3
};
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2010
01:55 AM
04-12-2010
01:55 AM
Good idea. Thanks!
Patricio.
Patricio.
