0Day Forums
Typecasting in Javascript - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: JScript (https://0day.red/Forum-JScript)
+--- Thread: Typecasting in Javascript (/Thread-Typecasting-in-Javascript)



Typecasting in Javascript - arthrodynicevdrxj - 07-24-2023

How to convert the following `Java` code to `JScript`:

return ((IPOSBasket) basket).getOriginalCashierID();

When executing the above code in `Java`, it works fine. But if I try to execute as a `JScript`, I am getting `NULL` value.



RE: Typecasting in Javascript - wharl93598 - 07-24-2023

At the risk of getting downvotes XD

>[Java and Javascript are similar like Car and Carpet are similar.][1]

>Greg Hewgill 2008

[1]:https://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java/245068#245068



RE: Typecasting in Javascript - gilgamesh477 - 07-24-2023

You shouldn't need to cast anything, how are you getting the basket variable?

Also, as a good practice don't do any operations in a return statement, it sometimes hides errors/problems in code and harms readability.

So if it is JScript:

var basket : IPOSBasket = IPOSBasket(x); // this is made up, don't know what you are doing here.
var originalCashierID = basket.getOriginalCashierID();
return originalCashierID;


RE: Typecasting in Javascript - burnedout294 - 07-24-2023

As mentioned by HMR in comment, the following line works fine:

return basket.getOriginalCashierID();