Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript void operator

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 340
    Comment on it

    The Javascript void operator set the given expression and then returns the output as undefined.

     

    The void operator is employed to amass the undefinable denoting price, typically we tend to use "void(0)" (which is suggests that "void 0"). In these cases, the global variable undefinable are often used instead.

     

    Suppose you've got an HTML document that uses href="JavaScript:Void(0);" within an <a> component. JavaScript void is commonly used once, inserting AN expression into an online page could generate an unwanted result.

     

    When using JavaScript:Void(0), you'll eliminate that unwanted result, as a result of it'll come the indefinable primitive value.

     

    A common usage of JavaScript:Void(0) is with hyperlinks.

     

    Whenever you would like to call JavaScript from within a link. once you click on a link, the browser loads a new page or refreshes identical page. however you do not want this to happen if you have connected some JavaScript to that link. 

     

    To prevent the page from refreshing, you'll use JavaScript:void(0).

     

    When a browser follows a javascript: address, it sets the code within the address so take away the contents of the page with the came back value, unless the came back value is undefinable. The void operator are often used to come undefined.

    For example:

     

    <a href = " javascript:void(0); ">
        
         Click here to do nothing!
    
    </a>

    Above code is used to cancel the unnecessary page load.

     

    <a href = " javascript:void(document.body.style.color = 'blue');">
       
        Click here to change the color of the content on click.
    
    </a>

    In above code we you click on the link the color of the content will change to green.

     

    <a href = " javascript:void(myNum = 10); alert('myNum = ' + myNum)">
    
        Set value
    
    </a>

    In above code we will be setting a value 5 to the MyNum variable.

     

    Happy Coding :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: