Introduction To JavaScript
Introduction To JavaScript
JavaScript is a scripting language that is used to create and manage dynamic web pages,
basically anything that moves on your screen without requiring you to refresh your browser. It
can be anything from animated graphics to an automatically generated Facebook timeline.
When most people get interested in web development, they start with good old HTML
and CSS. From there, they move on to JavaScript, which makes sense, because, these three
elements together form the backbone of web development.
HTML is the structure of your page like the headers, the body text, any images you
want to include. It basically defines the contents of a web page.
CSS controls how that page looks (it’s what you’ll use to customize fonts, background
colors, etc.).
JavaScript is the third element. Once you’ve created your structure (HTML) and your
aesthetic vibe (CSS), JavaScript makes your site dynamic (automatically updateable).
Features of JavaScript
There are following features of JavaScript:
1. All popular web browsers support JavaScript as they provide built-in execution
environments.
2. JavaScript follows the syntax and structure of the C programming language. Thus,
it is a structured programming language.
3. JavaScript is a weakly typed language, where certain types are implicitly cast
(depending on the operation).
4. JavaScript is an object-oriented programming language that uses prototypes
rather than using classes for inheritance.
5. It is a light-weighted and interpreted language.
6. It is a case-sensitive language.
7. JavaScript is supportable in several operating systems including, Windows,
macOS, etc.
8. It provides good control to the users over the web browsers.
JavaScript Variable
1. JavaScript variable
2. JavaScript Local variable
3. JavaScript Global variable
A JavaScript variable is simply a name of storage location. There are two types of
variables in JavaScript : local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
1. var x = 10;
2. var _value="sonoo";
1. var 123=30;
2. var *aa=320;
<script>
var x = 10;
var y = 20;
var z=x+y;
document.write(z);
</script>
OR
<script>
If(10<13){
var y=20;//JavaScript local variable
}
</script>
<html>
<body>
<script>
var value=50;//global variable
function a(){
alert(value);
}
function b(){
alert(value);
}
</script>
<button onclick="a()">press</button>
</body>
</html>
<html>
<body>
<script>
function m(){
window.value=100;//declaring global variable by window object
}
function n(){
alert(window.value);//accessing global variable from other function
}
m();
</script>
<button onclick="n()">press</button>
</body>
</html>
1)var:
<script>
var x = 10;
var y = 20;
var z=x+y;
document.write(z);
</script>
2)let:
<script>
let x = 10;
// Here x is 10
{
let x = 2;
}
document.write(z);
// Here x is 10
</script>
3)Const:
A new Array
A new Object
A new Function
A new RegExp
JavaScript is a dynamic type language, means you don't need to specify type of the
variable because it is dynamically used by JavaScript engine. You need to use var here
to specify the data type. It can hold any type of values such as numbers, strings etc. For
example:
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical
Operator Description Operators
Condition
al
Operators
+ Addition Type
Operators
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
++ Increment
-- Decrement
+= x += y x=x+y
-= x -= y x=x-y
*= x *= y x=x*y
/= x /= y x=x/y
%= x %= y x=x%y
**= x **= y x = x ** y
== equal to
=== equal value and equal type
!= not equal
? ternary operator
! logical not