Javascript Output Function in Hindi – Console Log, Window.alert

Javascript Output in Hindi

जब user कोई कोड लिखता है तब वो उसकी output देख कर पता करता है की उसके लिखे हुए code सही से काम कर रहा है या नहीं | या तो program सही result देगा या कोई error देगा | ये सब हम code के output से समझ सकतें हैं |

आप इस आर्टिकल में javascript program को कैसे देख सकतें या उसकी output कितने प्रकार से display हो सकती है वो सीखेंगे |

Javascript Output Types

javascript में output को display करने के लिए कई तरीकें हैं और उन तरीकों को, 4 methods से दर्शाया गया है और वो हैं :

  1. console.log()
  2. window.alert
  3. document.write
  4. innerHTML

console.log()

browser के console tab में output दिखाने के लिए ये method का उपयोग होता है | browser window में console tab के अंदर javascript output, console.log() method से देख सकतें हैं |

उदाहरण:

<!Document html>
<html>
 <head>
  <title>javascript output tutorial</title>
 </head>
 <body>
  <h2>JS tutorial</h2>
  <script>
   console.log("Hello World");
   var a=20;
   console.log(a);
  </script>
 </body>
</html>

उदाहरण में हमने normal text message और variable की value दोनों console.log() method के जरिये print करवाया है |

console.log() method से javascript की कोई भी data को display कर सकते हैं चाहे वो text हो या कोई variable की value या html content |

output:

js console.log example

नॉटपॉइंट : console.log() method का उपयोग ज्यादातर javascript programming में debugging के लिए किया जाता है | program में आ रहे error को programmer console tab में देख पाता है |

console tab में जाने के लिए keyboard में f12 key को press करनी पड़ती है | या फिर window पे right click करके inspect option में जाना होता है | तब side में एक बार open होगा उसमे console tab को select करनी पड़ती है |

window.alert()

javascript में window.alert() एक dialogue box की तरह काम करता है | user को कुछ जानकारी देने के लिए alert box का उपयोग होता है |

किसी बात के लिए user को सचेत करना हो जैसे की कोई input data सही से डाली नहीं गयी है और उसे देना जरुरी है | तब वो alert के जरिये user को बताई जा सकती है |

user को सचेत करने के साथ alert box का उपयोग output दिखाने के लिए भी की जाती है | window.alert() से output, popUp box में display होता है |

उदाहरण:

var a=20; 
var b=30;
var res = a+b;
alert(res);

output:

js alert box example

document.write()

document.write() method से webpage पे text दिखा सकतें हैं | इसके साथ साथ variables की value दिखाने के लिए और html tag को text के साथ print भी करवा सकतें हैं |

कोई mathmetical expression भी इस method के जरिये display करायी जा सकती है |

नॉटपॉइंट : document.write method js programming में ज्यादातर testing के purpose से उपयोग में आता है |

उदाहरण:

var a = 20; 
var b = 30;
var res = a+b;
document.write("result is " + res);

output:

js document.write example

innerHTML

innerHTML browser में id के basis पे content display करने के लिए उपयोग होता है | किसी element की id, getElementById() method से ली जाती है | और element को select करने के बाद उसके अन्दर की content को innerHTML के जरिये display की जाती है |

उदाहरण:

<!Document html>
<html>
 <head>
  <title>javascript output tutorial</title>
 </head>
 <body>
  <h2 id="heading">JS tutorial</h2>
  <button id="btn" onclick="btnclick()">Click</button>
  <script>
   function btnclick()
   {
     document.getElementById("heading").innerHTML="Javascript";
   }
  </script>
 </body>
</html>

उदाहरण में देखिये button click से heading को बदली गयी है | पेहले हम document.getElementById(“heading”) command से h2 tag की id उठाये | और innerHTML से जो भी output हम चाहतें थे वो value डाले |

जब button click होगा तब h2 का content बदल जायेगा |

output:

अन्य javascript tutorial के सुझाव

Leave a Comment