Sunday, 26 February 2023

Java Script Basics with Turn Light On and Off Example

 What is Java Script? 

JavaScript is a popular programming language that is widely used to create dynamic and interactive websites. It was first introduced in 1995 by Brendan Eich, a software engineer at Netscape, and has since become one of the most widely used languages on the web.

JavaScript is a high-level programming language that is used to add interactivity and functionality to web pages. It is often used in conjunction with HTML and CSS to create dynamic web pages that can respond to user input and change in real-time. It is a versatile language that can be used to create everything from simple animations to complex web applications.

One of the key features of JavaScript is its ability to manipulate the Document Object Model (DOM). The DOM is a programming interface that represents the structure of an HTML or XML document as a tree-like structure. By using JavaScript to manipulate the DOM, developers can create dynamic web pages that respond to user input and change in real-time.

JavaScript is also an object-oriented language, which means that it uses objects to represent data and behavior. This allows developers to create complex data structures and reuse code, making it easier to write and maintain complex applications.

Another key feature of JavaScript is its support for asynchronous programming. Asynchronous programming allows developers to write code that can run in the background, without blocking the main thread of execution. This is especially useful when working with web applications that need to make requests to a server or perform other time-consuming tasks.

One of the biggest advantages of JavaScript is its portability. Because it is a client-side language, it can run on almost any device with a web browser. This makes it a great choice for creating web applications that can be accessed from a variety of devices and platforms.

JavaScript is also an open-source language, which means that anyone can contribute to its development and improvement. This has led to a large and active community of developers who share their knowledge and resources to help others learn and improve their skills.

While JavaScript has many advantages, it is not without its challenges. One of the biggest challenges is the fact that it is an interpreted language, which means that it is not as fast as compiled languages like C++ or Java. This can make it more challenging to create high-performance applications.

Another challenge is the fact that JavaScript code can be difficult to debug. Because it is a dynamically typed language, it can be challenging to catch errors before they cause problems in the application.

Despite these challenges, JavaScript remains one of the most widely used languages on the web. Its versatility, portability, and ease of use make it a great choice for creating dynamic and interactive web applications. Whether you are a beginner or an experienced developer, learning JavaScript is a valuable skill that can help you create powerful and engaging web experiences.


Example 

<!DOCTYPE html>

<html>

<body>

<h2>What Can JavaScript Do?</h2>

<p>JavaScript can change HTML attribute values.</p>

<p>In this case JavaScript changes the value of the src (source) attribute of an image.</p>

<button onclick="document.getElementById('myImage').src='pic_bulbon.gif'">

Turn on the light

</button>

<img id="myImage" src="pic_bulboff.gif" style="width:100px">

<button onclick="document.getElementById('myImage').src='pic_bulboff.gif'">Turn off the light</button>

</body>

</html>







Refference 
https://www.w3schools.com/js/js_intro.asp


No comments:

Post a Comment