In this post we will start writing simple Javascript codes and run them on the browser. We will also look comments.
Two Lines Of Code
Our code is below. It is now two line and becoming more complex but not too much for our target.
console.log("Hello Poftut"); console.log("By Poftut");
- Here is two JavaScript line ended with ;
Comments
Writing explanations to the code is a good habit for a developer. Comments are used to add explanations to the code and Comments are not interpreted as code. They have no effect the working of code. Below we have added a comment to our single line code.
//This is single line comment console.log("Hello Poftut"); /* This is multi line comment */
- // used for single line comment. Only this this line is a comment
- /* */ are used multi line comment. Between these all text are just comment
JavaScript supports writing comments or notes about code without affecting the application. Comments are very useful because it gives more details and explanation to the code.
//Comment
- This is a single line comment with //
/* This is a multiline comment */
- This is a multiline comment. Multi-line comment starts with /* and ends with */
Case Sensitivity
Javascript is case-sensitive language. This means keywords, variables etc. all language elements differs with case status. Let me exlain with simple example FOR is different then for. As we see each word case is different. Keep in mind that Html is not case sensitive.
Literals
Literals is data values generally used to assign numeric or string values to the variables. Below are some of literals.
12 "Hi poftut" true
Keywords
JavaScript have keywords to operate language logic. For example to loop JavaScript provides while .
Semicolons
JavaScript code lines are terminated with semicolons. Semicolons are optional but to make code readable most of the developers use semicolons in their project.
var age=12;
- JavaScript code line ends with ;
Adding JavaScript Code To Html Pages
For learning purposes we will use Scratchpad but in the real world JavaScript code runs in the html pages. There is two main methods to run JavaScript code in the Html page.