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 8724989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:56:20+00:00 2026-06-13T07:56:20+00:00

Possible Duplicate: What does the exclamation mark do before the function? I’m maintaining an

  • 0

Possible Duplicate:
What does the exclamation mark do before the function?

I’m maintaining an existing site with a “tweet” button, which appears to come from this page

A colleague here brought up a great question: Why does this script tag reverse the (undefined via no return statement) value of this self-calling function? (pretty-fied for ease of reading, original is at link)

<script>
  !function(d,s,id) {
//^--- that
    var js,fjs=d.getElementsByTagName(s)[0];
    if(!d.getElementById(id)) {
      js=d.createElement(s);
      js.id=id;
      js.src="https://platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);
    }
  }(document,"script","twitter-wjs");
</script>

To my non-JS-pro eyes, that appears to be flipping the boolean value of undefined, thereby allowing the entire <script> tag to evaluate to true. For what it’s worth, that is a totally foreign idea to me (that <script> tag has an expression value).

My expectation is that there is some specific browser out there for which a <script> tag’s boolean value (yes, I feel crazy even typing that) matters.

So the basic question is this: Does a <script> have a meaningful “expression” value to any browsers you know of? and What is the implicit meaning of a true vs. false in this case?

  • 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-13T07:56:21+00:00Added an answer on June 13, 2026 at 7:56 am

    An explanation of what is going on and why…

    In Javascript, you have function statements and function expressions. The two of them are similar, but not exact.

    Function statement

    function myTest() {return true;}
    

    Function Expressions

    var f = function() {return true;}
    alert(f()); //
    
    alert(function() { return true}); // Return value is used
    
    // and even
    
    (function(x, y) {
      var z, x; // private variables, hidden from the outside scope
      var r = x  + y;
      // Return value is ignored.
    }(1, 2));
    
    // The ! can be used to start a function expression too.
    // This is totally legal Javascript, but it isn't in the normal
    // "vernacular" of the langage
    !function(x, y) {
      var z, z1; // Private vars
      // Do something with side effects
      // Return value is ignored.
    }(x, y);
    

    Updated due to comments

    //The following code works identical:
    var v1 = (function(a, b) {return a+b}(1,2));
    var v2 = (function(a, b) {return a+b})(1,2);
    var v3 = function(a, b) {return a+b}(1,2)
    

    I prefer the first form because it lets me use the block matching tools on my editor, and the f1 form is preferred by the sometimes useful programs JSLint and JSHint.

    All create a function expression and then invoke it immediately. In this case, the parens are not needed by the Javascript compiler, but they serve as a very useful hint to the reader that this is not a normal assignment.

    On the other hand, you must have something to tell the JS engine that you have a function expression instead of a function statement. The = sign above works, but when there is no assignment, you need to start off with some kind of operator, be it (+!

    !function(x, y) {alert(x, y)}(1, 2);
    

    The leading operator makes it an expression. The () in the above examples force it to an expression as well.

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

Sidebar

Related Questions

Possible Duplicate: What does the exclamation mark do before the function? What's the point
Possible Duplicate: What does the exclamation mark do before the function? If you look
Possible Duplicate: What does the exclamation mark do before the function? I saw a
Possible Duplicate: What does the exclamation mark do before the function? So I've come
Possible Duplicate: What does the question mark and the colon (?: ternary operator) mean
Possible Duplicate: When does invoking a member function on a null instance result in
Possible Duplicate: What does (function($) {})(jQuery); mean? For the function (function($){})(), I've seen it
Possible Duplicate: Does the Facebook 'like' have a limit? Facebook like button updates the
Possible Duplicate: Does the compiler continue evaluating an expression where all must be true
Possible Duplicate: Does anyone know of a good C# API for Subversion? I'm designing

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.