Important Notice:

Course Content
Switch Statement
0/1
break and continue Statements
0/3
Basic Form Validation in JavaScript
0/1
JavaScript & Angular JS (Chapter- 6) M2-R5.1
About Lesson

Way of Adding JavaScript:-

     HTML में Javascript को दो प्रकार से define किया जाता है 

1. Internal Javascript (inpage/inline):- इसमें जावास्क्रिप्ट के कोड को उसी पेज मे लिखा जाता है जहाँ पर html की कोडिंग की जाती है।

2. External Javascript:-

              External JavaScript file की जरुरत तब होती है जब हमे JavaScript का code बहुत ज्यादा लिखना हो। अगर हम वह JavaScript code HTML document में ही लिखते है तो वह complicated और manage करना कठिन हो जाता है।  इसलिए JavaScript की external file की जरुरत होती है।  External JavaScript में external file में <script> element की जरुरत नहीं पड़ती है, लेकिन उसे HTML Document में import करने के लिए <script> element के साथ-साथ ‘src’ attribute की value पर external file का path दिया जाता है। <script> element के src attribute की value ये .js इस extension वाली होती है।

Syntax:-    <script src=”path_of_external_js_file”></script>

Note:- यदि हम जावा स्क्रिप्ट को बॉडी सेक्शन में लिखते हैं, तो  पेज लोड होने के बाद यह execute होता है।  यदि हम जावा स्क्रिप्ट को हेड सेक्शन में लिखते हैं, तो यह पहले ही execute हो जाता है इसके बाद पेज लोड होता है।

 

Way of Adding JavaScript:-

                        Javascript is defined in two ways in HTML

1. Internal Javascript (inpage/inline):- In this, JavaScript code is written in the same page where HTML coding is done.

2. External Javascript:-

                External JavaScript file is required when we have to write a lot of JavaScript code. If we write that JavaScript code in HTML document itself then it becomes complicated and difficult to manage. Therefore, external file of JavaScript is required. In External JavaScript, <script> element is not required in the external file, but to import it into HTML document, the path of the external file is given along with the <script> element on the value of ‘src’ attribute. The value of src attribute of <script> element is of extension .js.

Syntax:-    <script src=”path_of_external_js_file”></script>

Note:- If we write JavaScript in the body section, it executes after the page is loaded. If we write JavaScript in the head section, it gets executed before the page is loaded.

error: Content is protected !!