JAVASCRIPT
INTRODUCTION TO JAVASCRIPT
• What is JavaScript?
• It is designed to add interactivity to HTML pages.
• It is a scripting language (a light weight programming language)
• It is an interpreted language (it executes without preliminary compilation)
• Usually embedded directly into HTML pages
• And , Java and Javascript are different
WHAT CAN A JAVASCRIPT DO?
• JavaScript gives HTML designers a programming tool:- simple syntax
• It can put dynamic text into an HTML page
• It can react to events
• It can read and write HTML elements.
• It can be used to validate data
• It can be used to detect the visitor’s browser
• It can be used to create cookies
- Store and retrieve information on the visitor’s computer.
• JavaScript can be used for Client-side developments as well as Server-side developments.
• Client-side:
• It supplies objects to control a browser and its Document Object Model (DOM).
• DOM-Document Object Model – represents the structure of an HTML or XML document as tree
like structure where each node represents part of the document such a elements , attributes and text
• Like if client-side extensions allow an application to place elements on an HTML form and
respond to user events such as mouse clicks, form input, and page navigation.
• Useful libraries for the client side are AngularJS, ReactJS, VueJS, and so many others.
• Server-side:
• It supplies objects relevant to running JavaScript on a server.
• For if the server-side extensions allow an application to communicate with a database, and provide
continuity of information from one invocation to another of the application, or perform file
manipulations on a server.
• The useful framework which is the most famous these days is node.js.
HOW TO LINK JAVASCRIPT FILE IN HTML ?
• JavaScript can be added to HTML file in two ways:
• Internal JS: We can add JavaScript directly to our HTML file by writing the code inside
the <script> tag.
• The <script> tag can either be placed inside the <head> or the <body> tag according to the
requirement.
• External JS: We can write JavaScript code in another files having an extension.js and then
link this file inside the <head> tag of the HTML file in which we want to add this code.
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Basic Example to Describe JavaScript
</title>
</head>
<body>
<!-- JavaScript code can be embedded inside
head section or body section -->
<script>
console.log("Welcome to GeeksforGeeks");
</script>
</body>
</html>
JAVASCRIPT SYNTAX
• JavaScript Syntax is used to define the set of rules to construct a JavaScript program
console.log("Basic Print method in JavaScript");
// Variable declaration
let c, d, e;
// Assign value to the variable
c = 5;
// Computer value of variables
d = c;
e = c/d;
• let num1 = 50
• let num2 = 50.05
•
• let str1 = "Geek"
• let str2 = 'Geeks’
• console.log(num1)
• console.log(num2)
• console.log(str1)
• console.log(str2