Learn JavaScript Tutorial
Our JavaScript lesson is invent for beginners and professionals both. JavaScript is used to create client-side active pages.
- JavaScript is the world’s most admired programming language.
- JavaScript is the arrange language of the Web.
- JavaScript is easy to learn.
- This lesson will teach you JavaScript from basic to advanced.
What is JavaScript?
JavaScript (js) is a object oriented programming language. It is used by several websites for scripting the webpages. Javascript can hide HTML elements. It is an interpreted, matured programming language that enables dynamic connected on websites when applied to an HTML document. JavaScript is the Programming Language for the Web .JavaScript can update and change both HTML and CSS. JavaScript can calculate, manipulate and validate data.
Client-side scripting
JavaScript is a client-side script, meaning the browser processes the code instead of the web server.It means that a web page need not be a static HTML, but can include programs that interact with the user, control the browser, and dynamically create HTML content.validate data before sending it to the web server, adjusting the interface in response to user feedback, and for implementing other advanced features. Since JavaScript is part of the browser.
Features of JavaScript
All popular web browsers support JavaScript as they provide built-in execution environments.
- The data type of a variable is determined at runtime rather than at compile time.
- It is a light-weighted and interpreted language.
- JavaScript has several built-in data types, including strings, numbers, Booleans, arrays, and objects. It also has built-in functions for working with these data types, such as
index Of()
for finding the index of a string in another string, andslice()
for extracting a portion of an array. - It is a machine readable language.
- It provides good control to the users over the web browsers.
Application of JavaScript
. It is mainly used for:-
- Smartwatch Apps.
- Dynamic decline menus.
- Web Servers.
- Server Applications.
- Displaying clocks. etc
Javascript foundamentals
- Hello,Word!
JavaScript programs can be inserted almost anywhere into an HTML document using the <script>
tag.
For instance:
<!DOCTYPE HTML>
<html>
<body>
<p>Before the script...</p>
<script>
alert( 'Hello, world!' );
</script>
<p>...After the script.</p>
</body>
</html>
You can run the example by clicking the “Play” button in the right-top corner of the box above.
The <script>
tag contains JavaScript code which is automatically executed when the browser processes the tag.
Modern markup
The <script>
tag has a few attributes that are rarely used nowadays but can still be found in old code:
- The
type
attribute:<script type=…>
- The old HTML standard, HTML4, required a script to have a
type
. Usually it wastype="text/javascript"
. It’s not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. But that’s an advanced topic. - The
language
attribute:<script language=…>
- This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
Comments before and after scripts.
- In really ancient books and guides, you may find comments inside
<script>
tags, like this:<script type="text/javascript"><!-- ... //--></script>
These comments hide JavaScript code from old browsers that didn’t know how to process the
<script>
tag. Since browsers released in the last 15 years don’t have this issue, this kind of comment can help you identify really old code.
- Code Structure
The first thing we’ll study is the building blocks of code.
Statements
Statements are syntax constructs and commands that perform actions.
We’ve already seen a statement, alert('Hello, world!')
, which shows the message “Hello, world!”.
For example, here we split “Hello World” into two alerts:
alert('Hello'); alert('World');
In most cases, a newline implies a semicolon. But “in most cases” does not mean “always”!
There are cases when a newline does not mean a semicolon. For example:
alert(3 +
1
+ 2);
The code outputs 6
because JavaScript does not insert semicolons here. It is intuitively obvious that if the line ends with a plus "+"
, then it is an “incomplete expression”, so a semicolon there would be incorrect. And in this case, that works as intended.
alert("Hello");
[1, 2].forEach(alert);
No need to think about the meaning of the brackets []
and forEach
yet. We’ll study them later. For now, just remember the result of running the code: it shows Hello
, then 1
, then 2
.
Now let’s remove the semicolon after the alert
:
alert("Hello")
[1, 2].forEach(alert);
If we run this code, only the first Hello
shows (and there’s an error, you may need to open the console to see it). There are no numbers any more.
That’s because JavaScript does not assume a semicolon before square brackets [...]
.
Here’s how the engine sees it:ent.
alert("Hello")[1, 2].forEach(alert);
Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after alert
for the code to work correctly.
This can happen in other situations also.
Let’s note once again – it is possible to leave out semicolons most of the time. But it’s safer – especially for a beginner – to use them.
- The modern mode,”use Strict”
- Variables
- Data types
- Interaction: alert, ptomptn ,confirm
- Type conversions
- basic operators , maths
- Comparisons
- Conditional branching: if, ‘?’
- Logical operators
- Nulllish coalscing operatos ‘??’
- loops: while and for
- The “Switch” statement
- Functions
- Functions expresions
- Arrow Functions , the basic
- Javascript specials
Code quality
- Debugging in the browsers
- Coding style
- Coments
- Ninja code
- Automated testing with mocha
- polyfills and Transpilers
Object: the basics
- Objects
- object references and copying