- The data type of a variable is determined at runtime rather than at compile time.
- It is a light-weighted and interpreted language.
index Of()for finding the index of a string in another string, and
slice()for extracting a portion of an array.
- It is a machine readable language.
- It provides good control to the users over the web browsers.
. It is mainly used for:-
- Smartwatch Apps.
- Dynamic decline menus.
- Web Servers.
- Server Applications.
- Displaying clocks. etc
<!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.
<script> tag has a few attributes that are rarely used nowadays but can still be found in old code:
- The old HTML standard, HTML4, required a script to have a
type. Usually it was
Comments before and after scripts.
- In really ancient books and guides, you may find comments inside
<script>tags, like this:
<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 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:
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
"+", 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
forEach yet. We’ll study them later. For now, just remember the result of running the code: it shows
Now let’s remove the semicolon after the
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.
Here’s how the engine sees it:ent.
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”
- Data types
- Interaction: alert, ptomptn ,confirm
- Type conversions
- basic operators , maths
- Conditional branching: if, ‘?’
- Logical operators
- Nulllish coalscing operatos ‘??’
- loops: while and for
- The “Switch” statement
- Functions expresions
- Arrow Functions , the basic
- Debugging in the browsers
- Coding style
- Ninja code
- Automated testing with mocha
- polyfills and Transpilers
Object: the basics
- object references and copying