Episode 1: Introduction to JavaScript
A deep dive into JavaScript and will try understand that what is JavaScript why we always use it for website creation.
๐ Introduction
JavaScript is a single-threaded, lightweight and cross-platform scripting language for web applications. JavaScript is well known for developing websites and many types of browsers also support it. JavaScript can be used for both client-side renderings as well as server-side renderings.
JavaScript is also called a high-level, dynamic, and interpreted programming language.
JavaScript has a large and active community of developers, also there are various popular libraries and frameworks like React.js, Angular.js, Jquery, Anime.js etc**.** available to create complex web applications.
OK, you may get confused with some terminologies that I used above, so let's understand them first.
๐ค Terminologies
There are lots of complex terms that I used like -
Single-Threaded
Lightweight
Cross-platform
Client-side renderings
Server-side renderings
High-level language
Dynamic language
Interpreted language
So lets us understand them one by one.
Single-Threaded: Single-Threaded means that these types of programming languages can execute only single tasks at a time. It can't execute multiple executions at a time.
For ex:
// suppose 2 statements are written here - let a=10, b=20; // these are two operations - let c=a+b; let d=a*b;
Here 2 operations,
let c=a+b;
andlet d=a*b;
are there, so in this case the interpreter can't execute these two operations simultaneously. It will firstly executelet c=a+b;
and when this operation will be executed successfully, the other onelet d=a*b;
will execute by the interpreter. This is called a single-threaded scripting language.Lightweight: Lightweight scripting language is a type of language that main focus is only speed for simple as well as complex web applications.
There are many lightweight programming languages like Python, Ruby, JavaScript etc.
Cross-platform: Cross-platform refers to the type of languages that we can use to build web applications for multiple platforms without doing any kind of platform-specific modifications.
Client-side renderings: Client-side rendering is a process of rendering the user interface on the client's computer means that the client's computer's web browser will download the HTML, CSS and JavaScript files from the server that will be required to generate the user interface.
In this process, the UI rendering and displaying of both processes happen on the client's web browser.
Server-side renderings: Server-side rendering is a process of rendering the user interface on the server computer means that the server computer will generate the user interface and then it will send the contents to the client to the client's web browser to be displayed.
High-level language: High-level language refers to a language that is not easily understood by computers, but is written in a format that is easily readable by humans.
For ex:- C, C++, Java etc.
Dynamic language: A dynamic programming language is a type of programming language in which the variable is created in the memory and the value is determined at the run time of the program.
For ex:- JavaScript, Python, PHP etc.
As the opposite of this if the variable is created in the memory and the value is determined at the compiled time then that type of language is called statically-typed language.
For ex:- C, C++ etc.
Interpreted language: An interpreted language is a type of programming language that is executed line by line.
Suppose there are 10 lines in my program but at line 4 there are some errors so, in that case, lines 1 to 3 will be successfully executed but from line 4 the execution will stop there because there are some errors at line 4.
Now, lets us understand how we can include the javascript file in our HTML file.
๐ค How to include a js file in HTML?
There are a total of two ways to include a JavaScript file in HTML.
Internal JS
External JS
๐ Internal JS
So if we want to include the JavaScript file using an internal method then we have to write syntax like the given below-
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
// Here you can write javascript code. This is how we can include javascript using internal method.
</script>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
๐ External JS
So if we want to include the JavaScript file using an external method then we have to write syntax like the given below-
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<script src="myScript.js"></script>
</body>
</html>
// here we can write javasript code and this file name should be "myscript.js"
// our javascript code
Now, lets us see the pros and cons of javascript.
๐ฅณ Pros:
Versatility: JavaScript can be used for a wide range of tasks, from simple front-end tasks like form validation to complex back-end tasks like server-side programming.
Interactivity: JavaScript allows for the creation of highly interactive and dynamic web interfaces, which can provide a more engaging user experience.
Easy to learn: JavaScript is a relatively easy language to learn compared to other programming languages, making it accessible to beginners.
Large community: JavaScript has a large and active community of developers, which means that there are plenty of resources and support available.
Cross-platform: JavaScript can be used on a wide range of platforms, including web browsers, mobile devices, and desktop applications.
๐ Cons:
Browser compatibility: JavaScript code can behave differently in different web browsers, which can make it difficult to create cross-browser-compatible applications.
Security risks: JavaScript code can be vulnerable to various security risks, such as cross-site scripting (XSS) attacks, if not implemented correctly.
Performance: JavaScript is an interpreted language, which means that it can be slower than compiled languages, especially when dealing with large amounts of data.
Limited functionality: JavaScript has some limitations when it comes to more complex programming tasks, such as manipulating large amounts of data.
Debugging can be difficult: Finding and fixing errors in JavaScript code can be difficult, especially when working with larger code bases.
That's all everyone. I tried to explain it in a very easy manner. I hope you understood everything about it.
Thanks to all...