Practice Session on JavaScript - Udemy Tools
- IDE - Sublime text
- The start point of an application (industry standards) should be named
- index.html
Section -1 ; Lecture 4 : an example : What Js can do ? When we embed it to Web page to add dynamic content to it.
- JS can change the content of HTML.
- JS can change the attributes of HTML tag.
- JS can show/hide content of HTML.
(Section1 Lecture 5) :Notes for WhereToPutJs.html
- In head section
- In body section
- External file and re-use it in our Html page (importing the file to HTML)
=>in head tag/ body tag------>
Defining Js in HTML page (can be defined either in head/body tag)
<script type ="text/javascript"> function myfunction() { //content } </script>//calling - for instance via a button click--> Try
Issue:- difficult to debug when we embed in html ,opt for 3rd option - making a new file extension .js
=>External file (html/js - easy to read and maintain this way)----->
- create a file - XXXX.js
function myfunction() {
//content
}
3. calling:
in the calling html
note - avoid scripting while loading the page i.e in the head tag! (consideration while performance is criteria)
Section-2 Lecture 1 : Notes for How to See Output from JS
Four Ways :
- window.alert() - Throws alert on the window for the user.A Method;accept input parameters
- document.write() - Used to write/update data on screen.A Method;accept input paramters
- innerHTML - Used to update the text in HTML.Just do assignment for this.
- console.log() - Important for development purpose ; Works silently without hindering user experience.A Method;accept input parameters.
Important point :
- using document.write after page loads will replace the content of the page(Must be avoided).
- to see the output for console.log - on browser > rt. click and click on inspect > console