- JavaScript is a high-level, interpreted and popular programming language.
- It is widely used for web development to create dynamic and interactive web pages.
- It is easily written inside HTML in script tag or in a seperate file and imported in HTML file.
- it give html web pages a dynamic behaviour.
- nowadays , We have javascript in server side as well which is used to write micro-services, web services with the help of javascript engine.
- there are a-lot of libraries and frameworks built on top of javascript. below are some of the example:
- React js
- Vue.js
- Angular js
- jQuery
- Ext.js
- Backbone.js
- Ember.js
- Meteor
- Mithril
- Node.js
- Polymer
- Aurelia
- react native etc.
Why Javascript ?
- Web/UI Development: JavaScript is widely used and popular for creating
- dynamic and interactive web pages
- creating pop-ups,
- animating elements
- manipulating the Document Object Model (DOM) etc.
- Server-side Services: JavaScript can be used for server-side development with technologies such as Node.js, allowing developers to build full-stack applications using only JavaScript.
- Mobile App Development: JavaScript can be used to develop hybrid mobile apps for iOS and Android platforms using tools like React Native.
- Game Development: JavaScript can be used to create 2D & 3D games for the web using frameworks such as Phaser and Babylon.js.
- Desktop Applications: JavaScript can be used to build cross-platform desktop applications using tools like Electron.
- Internet of Things (IoT): JavaScript can be used to develop applications for IoT devices, such as controlling sensors and actuators.
JavaScript – Syntax
1 2 3 4 5 |
<script type="text/javascript"> // Sample JavaScript code. </script> |
type − This attribute indicate the scripting language used. its an optional attribute.
JavaScript CodeEditor
You can use any IDE . I prefer Visual Studio Code.
- download Visual Studio Code from this link : https://code.visualstudio.com/
- once downloaded, Open Visual Studio Code.
- Click File in the top left corner.
- Click New File and Enter name as “index.html”. ( note: filetype of new file should be .html extension)
- Type the HTML JavaScript code you want to use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <p id="myDiv"></p> <script type="text/javascript"> //JavaScript start here inside script tag document.getElementById("myDiv").innerHTML = "Hello World !!"; </script> </body> </html> |
6. To run, Right click & click on “open with browser”.
7. You will see, output as: Hello World !!
Things about JavaScript
- JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs. you can free to use for formatting.
- Semicolons are optional in JavaScript.
both statement is same .
1 2 3 4 |
eg. var x=10 var x=10; |
3. JavaScript is a case-sensitive language.
4. support both single line and block comment.
syntax:
1 2 3 4 5 6 7 |
<script> // single line comment. /* block comment: * This is a multi-line comment in JavaScript */ </script> |