- Introduction to JavaScript syntax in Hindi
- First JavaScript program in Hindi
- Comments in JavaScript in Hindi
Introduction to JavaScript Syntax
किसी भी HTML program में JavaScript को add करने का syntax बहुत ही आसान है। इसके लिए आप <script> tag यूज़ करते है।
आप <script> tag को अपने HTML program में कंही भी add कर सकते है।
लेकिन Readability के लिए हमेशा ये suggest किया जाता है की आप इसे <head> tag के अंदर ही लिखे।
<script> tags से browser को पता चल जाता है की ये JavaScript code है और इसे कैसे interpret करना है।
<script> Tag Attributes
<script> tag के 2 attributes होते है। इन attributes के द्वारा आप scripting language और type define करते है।
- language – इस attribute से आप scripting language define करे है जैसे PHP और JavaScript आदि।
- Type – ये attribute necessary होता है इससे आप अपनी file का type define करते है जैसे की text/javascript.
इन attributes की मदद से आप <script> tag को define करते है।
Syntax
<script language="javascript" type="text/javascript">
// यँहा पर आप JavaScript code लिखते है।
</script>
ये JavaScript define करने का standard syntax रहा है। लेकिन अब यह standard syntax नहीं है।
आप चाहे तो language और type attributes के बिना भी <script> tag define कर सकते है। क्योंकि JavaScript को HTML के लिए default scripting language माना गया है।
अब आपको सिर्फ opening और closing script tags define करने की आवश्यकता होती है।
<script>
// यहाँ अपना JavaScript code लिखिए।
</script>
A Very First JavaScript Program
<!-- javascriptFirstProgram.html -->
<html>
<head>
<title>First JavaScript program</title>
</head>
<body>
<script>
// Printing message
document.write("Hello Universe!");
</script>
</body>
</html>
उपर दिए गए program में मैने एक HTML file में कुछ JavaScript code add किया है। ये एक बहुत ही simple program है।
सबसे पहले <body> section में <script> tag define किया गया है। <script> tag में write function को call किया गया है।
इस function में एक string pass की जाती है। ये function उस string को webpage पर show करता है। इसी तरह आप program में जँहा भी JavaScript add करना चाहते है कर सकते है।
Output

Commenting in JavaScript
JavaScript में single line और multi-line 2 तरह के comments होते है।
Single Line Comments
Single line comments आप double backslash (//) के द्वारा add करते है। इसका उदाहरण नीचे दिया जा रहा है।
<script type="text/javascript">
// This is a single line comment
some other JavaScript code here
</script>
Multi-line Comments
Multi-line comments आप एक back slash और * के द्वारा add करते है। इसका उदाहरण नीचे दिया गया है।
<script type="text/javascript">
/* This is a
multi-line comment*/
some other JavaScript code here
</script>
Previous: JavaScript Introduction
Next: JavaScript Variables