Hi Guys
I'm using 'use strict' in every function in a JavaScript file but the solution checker will still pick up a medium severity issue i.e. Use strict mode when possible. How do i go about making this go away? Or is this a known issue.
Hi Guys
I'm using 'use strict' in every function in a JavaScript file but the solution checker will still pick up a medium severity issue i.e. Use strict mode when possible. How do i go about making this go away? Or is this a known issue.
I know this is an ancient question by the standard of this board, but I thought I'd share for the future: the solution checker warns you when you're not using "use strict" --- AND when you're using it incorrectly.
I had thrown a bunch of "use script"s in there to make it go away -- and still failed. I used JSHint in VSCode, which highlighted my unnecessary ones, and when I removed the unnecessary ones, the "web use strict" warning went away.
I just tested that on the beginning of the script, and inside the function. Both failed. The error keeps poping. Any suggestions at this point?
Thanks
Hi Tia,
This is one known issue.
How do you enable strict mode?
Simple. Toss this at the top of a program to enable it for the whole script:
"use strict" ; |
Or place it within a function to turn on strict mode only within that context.
function imStrict(){ "use strict" ; // ... your code ... } |
ECMAScript 5 Strict Mode: https://johnresig.com/blog/ecmascript-5-strict-mode-json-and-more/
Currently you have to 'use strict' within every new function But not at top level.
function imStrict(){ "use strict" ; // ... your code ... } |
https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/374113/why-does-solution-checker-not-recognize-use-strict-in-the-beginning-of-a-javascript-webresource
If you still met the issue please raise one ticket for escalation. Appreciate.
Following doc list the MS Best practice rules used by solution checker
https://docs.microsoft.com/en-us/powerapps/maker/common-data-service/use-powerapps-checker#best-practice-rules-used-by-solution-checker
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode/Transitioning_to_strict_mode
Strict mode is a way to introduce better error-checking into your code. Code should run in strict mode wherever possible. This is a JavaScript warning.
Add use strict to the JavaScript file, this link explains it more detail
According to this article it Strict mode helps :
It catches some common coding bloopers, throwing exceptions.
It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object).
It disables features that are confusing or poorly thought out.
Should you use single or double quotes e.g.
‘use strict’;
or
“use strict”;
In JavaScript, it doesn’t matter if you use single or double quotes, here for more details
To invoke use strict for the whole file, place it before any other JavaScript statements. It’s possible to apply use strict for specific functions.
Reference Blog:https://crmbusiness.wordpress.com/2020/01/16/what-the-solution-checker-does-and-why-you-should-use-it/
Hope above would hlep.
Regards
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,252 Super User 2024 Season 2
Martin Dráb 228,089 Super User 2024 Season 2
nmaenpaa 101,148