javascriptjqueryfacebookasynchronouslabjs

Uncaught SyntaxError: Unexpected token if


I am getting the error specified in the question title for the following code snippet :

$LAB.queue(function init() {
    FB.init({
        appId: '00000000',
        status: true,
        cookie: true,
        xfbml: true,
        logging: '0'
    });
}
if(window.FB) {
    init();
} else {
    window.fbAsyncInit = init
});

Any ideas as to what might be causing the error? I just cannot figure out the issue.


Solution

  • If you need to call init anywhere in your script, define it separately and suppy it to your queue() call. Also please change your question to indicate your requirement rather than just saying you need help fixing syntax error...

    var init = function() {
        FB.init({
            appId: '00000000',
            status: true,
            cookie: true,
            xfbml: true,
            logging: '0'
        });
    };
    
    $LAB.queue(init);
    
    if(window.FB) {
        init();
    } else {
        window.fbAsyncInit = init
    }