kernal
kernal

Reputation: 101

equal not work in the javascript

I am using Codemirror and I want to define my own mode , I am using the function stream.skipTo(")") which it return true if the stream match ")" if not return undefined ... the function work fine But I can't get the return type for this function

my code :

CodeMirror.defineMode("mymode", function() {

    return {
        token: function(stream,state) {

            if (stream.match("aaa") ) {
                return "style1";
            } else if (stream.match("bbb") ) {
                return "style2";
            }
                        if ( stream.match("(")) {

            stream.skipTo(")");
            var ggg=stream.skipTo(")");
           alert(ggg);

            if(ggg==="undefined")
            {
            alert("fff");
            }

              return null;
    }
            else {
                stream.next();
                return null;
            }
        }
    };

});


var editor = CodeMirror.fromTextArea(document.getElementById('cm'), {
    mode: "mymode",
    lineNumbers: true
});

Explain what code do : if you write on editor "(" and write any character the function stream.skipTo(")") return undefined until you write the character ")" it return true .

my problem :

when I save the return type of function in var ggg it saved correct But when I write the instruction if(ggg==="undefined") it never works.

Why the instruction if(ggg==="undefined") doesn't work??

my try online

Upvotes: 0

Views: 87

Answers (1)

parwatcodes
parwatcodes

Reputation: 6796

if (ggg === "undefined") statement means you are performing strict equality check with string as you have bounded the undefined with quotes

Do if(ggg === undefined) to check with undefined type


undefined docs from MDN

Upvotes: 2

Related Questions