Note 2: Basics of JS

 Setting Up the Development Environment :

  • In order to write a Java script, you need any code editor. There are several code editors are available in the market. like,  VS-Code, Sublime, or Atom.
  • Here , one of them is Vs-Code we can easily download from code.VisualStudio.com

  • another this is I want to install is Node. we can download it from nodejs.org.

  • Technically we don't need Node to run Javascript. because you can run your JavaScript code inside of the browser or Node. but, it is good to install Node in the machine because it is basically used to install third-party libraries.
  • I have installed all things then I had created a new folder on the desktop name as "Basic-JS". and then I open VS-Code. after that, I create a new Html file named Index.Html. also, I have installed live server in vs code. so the browser will get updated as quick when I save my file.



  • So, Basically, we are done with how to get started with the Basics of JavaScript. here I have to explain the required things to developed basic javascript.

First JavaScript program.
  • In order to write JavaScript, we need a script element. there are two places when you can add script elements. we can add Script Tag inside the Head Section or Body Section of HTML.
  • The best practice is to put the script tag inside the body section after completing all the element tags. Because the first reason is browser parses the HTML file from top to bottom so if we put the script tag in the head section there are chances that we have lots of JavaScript code in the head section so the browser may get busy in parsing javascript code and then it won't able to render the page. so, it will create a bad user experience. and another reason almost always codes we have in between this script elements needs to talk to the elements on this web page, for example, we may hide or show any element here in the web page so by adding script tag at the end of the body tag gives confident to render all the elements by the browser.



  • also, we can separate this code in a separate Javascript file. because there are chances that in future we have thousands of lines of code.




Run JS Code in Node.

  • open up the TERMINAL window and write node $filename$. here in my case, I am using 
  • node index.js.






Comments

Popular posts from this blog

NOTE 1: JavaScript introduction

Note 5: Arrays.

Note 6 : Functions