JavaScript is a dynamic scripting language that empowers developers to craft content that updates dynamically, manage multimedia, animate images, and much more.
While it might not handle every task imaginable, the power of JavaScript shines through in its ability to accomplish remarkable feats with just a few lines of code.
By using JavaScript, we can create:
- Web Applications or Web Sites
- Mobile Applications
- Desktop Applications
- Gaming Applications
- Data Visualization Applications
- Browser Extensions and More...
Yes, We can create server-side applications using JavaScript. Initially, JavaScript was used to create client-side applications, but with the help of Node.js, JavaScript can now able to create server-side applications as well
We can add JavaScript code into an HTML document using the <script> tag. We can add the <script> tag either in the <body> section or <head> section
Adding Inline JavaScript: We can add JavaScript code directly within an HTML document using the <script> element with the type attribute set to "text/javascript"
<body>
<h1>Hello, world!</h1>
<script type="text/javascript">
// JavaScript code goes here
alert("This is an inline JavaScript alert!");
</script>
</body>
Adding External JavaScript: We can also link an external JavaScript file to your HTML document using the script element's src attribute. This is commonly used for larger scripts or scripts that.
<head>
<title>Adding External JavaScript</title>
<script src="validations.js" type="text/javascript"></script>
</head>
- Adding
<script>
tags in the<head>
section ensures that browsers load and parse JavaScript code before rendering the page content, improving load times and performance. - Scripts loaded in the <head> section have a global scope by default. This means that any functions or variables declared within these scripts are accessible throughout the entire document, including other scripts and functions.
- Some scripts need to be initialized or configured before the content of the page is rendered.
- We can get access to all the DOM elements so that we can select and update the DOM elements
- Loading scripts at the end of the
<body>
section can lead to a more optimized page load sequence
We have three different keywords to declare the variables in JavaScript: var
, let
, and const
.
var subject = "JavaScript";
let age = 35;
const CITY = "London";
var: Variables declared with var
are function-scoped or globally scoped. They can be re-declared and updated within their scope.
let: Variables declared with let are block-scoped. They can be re-assigned within their scope, but not re-declared
const: Variables declared with const are also block-scoped. They cannot be re-assigned or re-declared.
Note: if the variable is an object or array, its properties or elements can still be modified.
Primitive Data Types:
- Number
- String
- Boolean
- Null
- Undefined
- Symbol
Non-Primitive Data Types (Reference Types):
- Object
- Array