# Javascript bug if (...) return 0; else { }

**URL:** <https://forum.juce.com/t/javascript-bug-if-return-0-else/16787>\
**Category:** General JUCE discussion\
**Created:** [February 25, 2016, 10:32am UTC](https://forum.juce.com/t/javascript-bug-if-return-0-else/16787 "2016-02-25T10:32:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gyohng](https://avatars.discourse-cdn.com/v4/letter/g/b5a626/32.png) [@gyohng](https://forum.juce.com/u/gyohng)\
**Post date:** [February 25, 2016, 10:32am UTC](https://forum.juce.com/t/javascript-bug-if-return-0-else/16787/1 "2016-02-25T10:32:39Z")

</div>

Hello Jules,

Something like this trips Juce JS parser:

```
if (a==0) return 0; else return 1;
```

From what it looks like to me, the return statement parser does not take the semicolon after the expression. If I remove the semicolon before else, then it works.

&nbsp;

Also the '||' operator does not behave like in other Javascript compilers in relation to undefined. For example:

```
return arr[tooLargeIndex] || defaultValue;
```

The above in Google V8 will return defaultValue.

&nbsp;

And I also suggest implementing typeof operator. I implemented it as a function for my own code, but it requires using parentheses.

```
static var jstypeof(const var::NativeFunctionArgs &a)
    {
        if (a.numArguments<1) return var("undefined");
        if (a.arguments[0].isUndefined()) return "undefined";
        if (a.arguments[0].isVoid()) return "void";
        if (a.arguments[0].isString()) return "string";
        if (a.arguments[0].isInt() || a.arguments[0].isInt64() || a.arguments[0].isDouble()) return "number";
        if (a.arguments[0].isObject()) return "object";
        return "unknown";
    }
```

Thanks,

George.
