JavaScript
JavaScript is a lightweight, cross-platform, single-threaded, and interpreted compiled programming language. It is also known as the scripting language for web pages. It is well-known for the development of web pages, and many non-browser environments also use it. JavaScript allows you to implement complex features on web pages. This means with the help of JavaScript we can add functionality to our websites.
Why JavaScript is known as a lightweight programming language?
JavaScript is considered lightweight due to the fact that it has low CPU usage, is easy to implement, and has a minimalist syntax. Minimalist syntax as in, has no data types. Everything is treated here as an object.
Single-threaded language?
Js is a single-threaded language means it can only execute a single line of code at a time. It makes it easy to write code that is both efficient and easy to understand.
Despite being single-threaded, JavaScript can still achieve some of the benefits of multi-threading through the use of asynchronous programming. Asynchronous programming allows JavaScript code to run in the background while other code is executing.
What is a Scripting language?
There are two types of languages:
Scripting Language
Compiled Language
scripting language is a programming language that is interpreted rather than compiled. This means that the code is translated into machine code when it is run, rather than before. They do not require the compilation step. An example of Scripting languages includes: JavaScript, Python, Ruby, PHP, Node.js
Compiled languages are converted directly into machine code that the processor can execute. As a result, they tend to be faster and more efficient to execute than interpreted languages. They also give the developer more control over hardware aspects, like memory management and CPU usage. Examples of pure compiled languages are C, C++, Erlang, Haskell, Rust, and Go.
Now How to link JS with HTML?
JavaScript can be added to HTML files 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 other 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>
<!-- External JS file link -->
<script src="myscripts.js"></script>
<title>
Basic Example to Describe JavaScript
</title>
</head>
<body>
<!-- Internal JS -->
<script>
console.log("Welcome to GeeksforGeeks");
</script>
</body>
</html>
Features of JavaScript
javascript was created in the first place for DOM manipulation. Earlier websites were mostly static, after JS was created dynamic Web sites were made.
Functions in JS are objects. They may have properties and methods just like other objects. They can be passed as arguments in other functions.
Can handle date and time.
Performs Form Validation although the forms are created using HTML.
No compiler is needed.
Applications of JavaScript
Web Applications
Server Application
Mobile Application
Games
SmartWatches
Machine Learning