Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:19:07+00:00 2026-06-13T22:19:07+00:00

I am defining the following function in my JavaScript: function _snr(id) { use strict;

  • 0

I am defining the following function in my JavaScript:

function _snr(id) {
    "use strict";
    this.e = "something";
}

I ran my code through JSLint and it suggested that I add “use strict” to the function.

When I do e now throws and undefined error. From some initial investigation it looks as though this which used to refer to _snr is no longer defined.

I have read about “use strict” and discovered that it is used to prevent unsafe practices. Could some one explain what was unsafe about this? What “use strict” is actually doing and how I can fix my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:19:08+00:00Added an answer on June 13, 2026 at 10:19 pm

    If a function is called without setting its this, in non–strict mode its this will be set to reference the global (window in a browser) object. In strict mode, it wil remain undefined.

    If your function is called as _snr(...) then its this is not set, so in non–strict mode this will be set to the global object so this.e = ... references (or creates due to the assignment) a global e property.

    However, in strict mode this will be undefined, and trying to access a property of undefined throws an error.

    It’s explained in ECMA-262 §10.4.3 Entering Function Code.

    Edit

    If you wish to access the global object from inside a function in a manner that is consistent with both strict and non–strict mode, you can use something like:

    var _snr = (function(global) {
        return function (id) {
            global.e = "something";
        };
    }(this));
    

    In non-strict mode, you can do:

    function _snr(id) {
        var global = (function(){return this;}());
        global.e = "something";
    }
    

    so that global within the function references the global object and you don’t have to worry about how the function is called. But the second example won’t work in strict mode.

    Other answers:

    I have read about “use strict” and discovered that it is used to prevent unsafe practices. Could some one explain what was unsafe about this?

    Absolutely nothing in this particular case.

    However, in a more general case, it was considered a good idea to be able to execute code within a context that stopped it accessing the global object directly. The second example above shows how that can be done in non–strict code (i.e. how you can get direct access to the global object from inside a function context).

    What “use strict” is actually doing

    It is stopping this being set to the global object if the call sets it to undefined or null. See above for the consequence of that.

    and how I can fix my code?

    See above.

    Oh, and finally, there is an informative summary of strict mode in ECMA-262 Annex C The Strict Mode of ECMAScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does the following javascript code mean? I guess it's defining a function within
I'm defining a javascript object via the following function: function Window(vars) { this.div =
I made the following function in SQL Server 2008 earlier this week that takes
I have the following code defining a Functor template and the function running_op, which
I have the following JS code: var Item = function () { this.property =
Conside the following JavaScript code. The function definitions all seem to achieve the same
I have the following function that takes this frequency parameter and calls the api,
JavaScript For example, I have the following JavaScript code (Dojo 1.6 is already loaded):
In jQuery, I have seen both the following ways of defining a jQuery function:
This question is more on javascript principle. function done(){ console.log('done defined with `function done(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.