It is also an untyped or dynamically typed language which means that you don’t need to declare variables along with their data types like other programming languages like C, C++, and Java which are statically typed.
In JS, you just need to write keywords either var, let, or const along with the variable name. For example –
var a; let b; const c = 10;
- Nowadays, JS has become a powerful programming language that is also used as a Backend Language with the help of NodeJS which is built on Chrome’s V8 Engine.
A parser is used to parse the code line-by-line (because JS is an interpreted language) and checks for syntax and errors, if there exists some error then it stops parsing & throws an error otherwise it produces a data structure known as Abstract Syntax Tree (AST).
Abstract Syntax Tree translates JS code to Machine Code and finally, the code is executed on the client’s browser.
- Used in form validation like checking empty input field, password length, etc.
- Used in the field of Web development, Mobile Development and Desktop App Development.
- Nowadays, it is used as a server-side scripting language with the help of NodeJS.
- They are used to add functionalities to web pages.
- It is also used in Game Development.
- Used to change the appearance or presentation of a web page.
- Basics of HTML and CSS.
- Any Code editor such as Notepad, Notepad++, VS Code, Sublime Text, etc.
- A Web Browser.
<!DOCTYPE html> <html> <head> <title>Document</title> </head> <body> <script> document.write('Hello'); </script> </body> </html>
We include this file inside the HTML file using the script tag.
Create two files with the names “index.js” and “index.html” and fill those files with the following content.
1. Using document.write()
Displaying message in HTML document.
2. Using console.log()
Prints message in the browser console.
Comments in the program are used to make it readable and understandable.
It is used to explain or describe a program and is never executed by an interpreter.
1. Single-line comment
Starts and ends with //.
// Printing message document.write("Hello World!");
2. Multi-line comment
Starts with /* and ends with */.
/* This is a multi-line comment. Printing message */ document.write("Hello World!");