aspx Tutorial

NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services,
Advertise Here

Toolbar

Get our toolbar!

Advertize



Posted by Aamir Hasan   on Wednesday, June 26, 2013 Total Views:  

In this example, we will see how to check undefined object property in JavaScript. When we will call a property in JavaScript without declaring, it will always give an error shown in below screen.

 

Let's, call a variable property and we will use typeof operator to check variable is not defined as shown below.

if (typeof aamir === "undefined") {

                alert("aamir object is undefined");

            }

 

 


Here’s example

 

<html>

<head runat="server">

    <title></title>

    <script type="text/javascript">

        function undefinedOP() {

            if (typeof aamir === "undefined") {

                alert("aamir object is undefined");

            }

        }

        function OPL() {

            var aamir = 'test';

            if (typeof aamir === "undefined") {

                alert("aamir object is undefined");

            } else {

                alert(aamir.length);

            }

        }

    </script>

 

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <input type="button" value="undefined object property" onclick="undefinedOP();"/>

            <input type="button" value="object property length" onclick="OPL();"/>

        </div>

    </form>

</body>

</html>

 

Output

 

Demo

Click here to see demo

Tags:
Category: All | asp.net | Javascript
Protected by Copyscape Online Plagiarism Tool

Comments (1) -

Fausto Grills
Fausto Grills United States
7/13/2015 8:26:41 AM #

Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new to the whole thing. Do you have any points for newbie blog writers? I'd certainly appreciate it.|

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5