sajad torkamani

Declare a helper function at the global level:

function isStrictMode() {
  return typeof this === 'undefined'
}

function isSloppyMode() {
  return this instanceof Window 
}

If JavaScript code is running in strict mode, this will always be undefined if unspecified.

Now, you can do something like:

if (isStrictMode()) {
  console.log('Running in strict mode')
}

if (isSloppyMode()) {
  console.log('Running in sloppy mode')
}

Sources/related

Tagged: JavaScript