Module V: Introduction to Java Script
Role of java script in a web page, Script writing basics, Adding interactivity
to a web page, creating dynamic web pages, Similarities to java,
embedding JavaScript code, embedding java applets in a web page, Form
validation using java script
Introduction to JavaScript:
JavaScript is a versatile, dynamically typed programming language that
brings life to web pages by making them interactive. It is used for building
interactive web applications, supports both client-side and server-side
development, and integrates seamlessly with HTML, CSS, and a rich
standard library.
JavaScript is a single-threaded language that executes one task at a
time.
It is an interpreted language which means it executes the code line
by line.
The data type of the variable is decided at run-time in JavaScript,
which is why it is called dynamically typed.
"Hello, World!" Program in Browser Console
A "Hello, World!" program is the simplest way to get started with any
programming language. Here’s how you can write one using JavaScript.
<html>
, <head>
<title>Javascript</title>
</head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>
In this example
The<script> tag is used to include JavaScript code inside an HTML
document.
console.log() prints messages to the browser's developer console.
Open the browser console to see the "Hello, World!" message.
"Hello World" Program in Server Console
We can also print the "Hello World" program directly into the console
terminal without embedded it into HTML. Create an index.js file and add
the code to it.
// This is a comment
console.log("Hello, World!");
Run it in your terminal with:
node hello.js
Output:
Hello, World!
Comments in JavaScript
Comments are notes in your code that the JavaScript interpreter ignores.
They’re great for explaining what your code does or for testing purposes.
Single-line comment: Starts with //
// This is a single-line comment
Role of java script in a web page, Script writing basics, Adding interactivity
to a web page, creating dynamic web pages, Similarities to java,
embedding JavaScript code, embedding java applets in a web page, Form
validation using java script
Introduction to JavaScript:
JavaScript is a versatile, dynamically typed programming language that
brings life to web pages by making them interactive. It is used for building
interactive web applications, supports both client-side and server-side
development, and integrates seamlessly with HTML, CSS, and a rich
standard library.
JavaScript is a single-threaded language that executes one task at a
time.
It is an interpreted language which means it executes the code line
by line.
The data type of the variable is decided at run-time in JavaScript,
which is why it is called dynamically typed.
"Hello, World!" Program in Browser Console
A "Hello, World!" program is the simplest way to get started with any
programming language. Here’s how you can write one using JavaScript.
<html>
, <head>
<title>Javascript</title>
</head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>
In this example
The<script> tag is used to include JavaScript code inside an HTML
document.
console.log() prints messages to the browser's developer console.
Open the browser console to see the "Hello, World!" message.
"Hello World" Program in Server Console
We can also print the "Hello World" program directly into the console
terminal without embedded it into HTML. Create an index.js file and add
the code to it.
// This is a comment
console.log("Hello, World!");
Run it in your terminal with:
node hello.js
Output:
Hello, World!
Comments in JavaScript
Comments are notes in your code that the JavaScript interpreter ignores.
They’re great for explaining what your code does or for testing purposes.
Single-line comment: Starts with //
// This is a single-line comment