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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:38:28+00:00 2026-05-29T17:38:28+00:00

I have the following jQuery function: function deleteHype(){ FB.api(‘/me/launchhype:hype’, function(response) { $.each(response.data, function(i, obj){

  • 0

I have the following jQuery function:

function deleteHype(){
    FB.api('/me/launchhype:hype', function(response) {
            $.each(response.data, function(i, obj){
                    if (obj.data.launch.url == '<?php the_permalink(); ?>') {
                            var delete_launch_id = parentObj=obj.id;
                    }
            });
    });
}
alert(delete_launch_id);

Lets say in the IF statement the var “delete_launch_id” is “X”. Well if I try to do the alert “delete_launch_id” outside the function it is “undefined”. I want it to give me back “X” (the hypothetically value that was set).

How can I do this? I’m lost and can’t seem to find a similar example.

  • 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-05-29T17:38:37+00:00Added an answer on May 29, 2026 at 5:38 pm

    By popular demand, here’s a more in depth look at why the variable “delete_launch_id” isn’t available at the point where it’s accessed by the “alert” function.

    There’s a couple things going on.

    First, the FB.api function is most likely an asynchronous AJAX call. JavaScript isn’t truly asynchronous (yet), but in this case, it effectively behaves so. What that means is that when asynchronous code executes, code after it will continue executing while the async code waits for a response. So, there’s a good chance that if you call “deleteHype”, and then “alert” immediately following it, FB.api response won’t have returned by the time “alert” is called. And as such, anything set within that async code won’t be available yet.

    The second issue is that JavaScript has “functional scope.” What that means, in practice, is that a variable defined inside a function is only available inside that function. It only has “scope” within that function. Consider the following code:

    var foo = 1;
    if(1 === 1) {
        // non-function block. foo is accessible in here, and any changes to foo will be seen outside this block.
        foo = 2;
    }
    // foo is 2
    
    function change() {
        // functional scope. variables defined in here are only available here
        foo = 3;
        var bar = 1;
    }
    
    // foo is 2 because we haven't called change yet
    // bar is "undefined"
    
    change();
    
    // foo is 3
    // bar is "undefined"
    

    “foo” changed because it had scope outside the function, so the function can access it.
    “bar” however, only has scope inside that function and doesn’t exist anywhere else.

    In the original example, “delete_launch_id” is declared inside several functions, actually, so it is not available anywhere else.

    My first answer addresses these issues by passing a function into the “deleteType” function as a “callback” that will be called only when the async code is finished and returns. That handles issue #1. The callback function then has “delete_launch_id” passed to it, which makes it available. The format I gave may seem a little weird:

    deleteHype(function(delete_launch_id) {
        // alert
    });
    

    What’s going on here is that we’re actually passing a function as a variable. It’s an “anonymous” function (no name). So deleteType treats is like a variable (because it is), and can call it, because it’s a function, and the code inside it will execute when it’s called. It’s a really handy pattern.

    I hope that helps a bit. This is confusing stuff at first.

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

Sidebar

Related Questions

I have following jQuery .each loop : $('.table-data tbody tr td').each( function(index) { $('.table-data
Ok. I have the following jQuery code jQuery(function(){ jQuery.get('/GalleryPage.aspx?gallery=1234', {}, function(data) { galleryXML =
I have the following JQUERY: $(function() { $('span .breadcrumb').each(function(){ $('#footer').addClass($(this).text()); }); }); So it
I have the following jQuery Code: $(#menu span).click(function() { var url = this.getAttribute(data-url); var
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following jquery function for filtering the contents of a listbox on
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have the following jQuery function: $(function(){ if ($(.menu li).hasClass(active)) { $(.active).css(margin-top, 6px); }
I have the following scenario jQuery('#content').fadeOut('slow',function(){ jQuery('#content').load(detail.php?product=+imgID+&category=+cat); jQuery('#content').fadeIn('fast'); }); My problem however is that
I have the following jQuery: $(document).ready(function () { $(.element).draggable(); $(.element).droppable({ drop: function () {

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.