Skip to content

3. how to display output in javascript in Hindi?

    how to display output in javascript

    how to display output in javascript

    JavaScript मे output को different तरीको से display करा सकते है।

    • innerHTML का use करके
    • document.write() का use करके
    • window.alert() का use करके
    • console.log() का use करके

    innerHTML का use करके

    अगर आप HTML element को access करना चाहते हो तो आप document.getElementById(id) method का use कर सकते हो।

    यहा id attribute HTML element को define करता है। innerHTML property HTML content को define करती है।

    उदाहरण

    <!DOCTYPE html>
    <html>
    <body>
    <h1>innerHTML</h1>
    <p>how to display output in javascript</p>
    <p id="one"></p>
    <script>
    document.getElementById("one").innerHTML = 3+2;
    </script>
    </body>
    </html>
    

    document.write() का use करके

    आप testing purpose के लिए document.write() का इस्तेमाल कर सकते हो।

    <!DOCTYPE html>
    <html>
    <body>
    <h1>document.write</h1>
    <p>how to display output in javascript</p>
    <script>
    document.write(5 + 9);
    </script>
    </body>
    </html>
    

    HTML document load होने के बाद document.write() का इस्तेमाल करना HTML को deleat कर देता है।

    उदाहरण

    <!DOCTYPE html>
    <html>
    <body>
    <h1>document.write</h1>
    <p>how to display output in javascript</p>
    <script>
    <button type="button" onclick="document.write(5 + 9)">click here</button>
    </script>
    </body>
    </html>
    

    window.alert() का use करके

    alert box को display कराने के लिये आप window.alert() का use कर सकते है।

    उदाहरण

    <!DOCTYPE html>
    <html>
    <body>
    <h1>window।alert</h1>
    <p>how to display output in javascript</p>
    <script>
    window.alert("hi how are you");
    </script>
    </body>
    </html>
    

    console.log() का use करके

    debugging purpose के लिये console.log() method का इस्तेमाल करते है।

    debugging के बारे मे हम अगले लेख मे detail मे जानेंगे।

    उदाहरण

    <!DOCTYPE html>
    <html>
    <body>
    <h1>console.log</h1>
    <p>how to display output in javascript</p>
    <script>
    console.log(5 + 9);
    </script>
    </body>
    </html>
    

    output को देखने के लिये आप F 12 key press करे उसके बाद उसमे console को select करे।

    Next : Javascript Statements in Hindi

    Leave a Reply

    Your email address will not be published. Required fields are marked *