JavaScript is the world’s most popular programming language. Some of the advantages of javascript are given below:
- Client side execution
- Validation on browser
- Easy language
Disadvantages:
- It is comparatively less secure.
- No hardware access
Ways of adding javascript:
Inline – We can javascript inside the head tag or the body tag between <script>…</script>.
External – We can create a javascript file externally and link it inside the head tag or the body tag between <script>…</script>.
To link a java file to html file:-
<script src=”abc.js” type=”text/script”> </script>
Some of the functions of javascript is given below:-
- Write function
*document.write()
- It displays the content into page.
- If we use this function in the end of the HTML document it will delete all existing HTML.
- It is used only for testing purpose.
Ex:- document.write(variable); , document.write(4+2);
- Alert function
*window.alert()
- It displays the data in the alert box.
- It should be used when you want the user to stop and see the alert.
Ex:- window.alert(“hello world”); , window.alert(“4+2);
- Identifiers
It is a name having few letters, numbers and special characters.
It is used to identify var, function, symbolic constant and so on.
Ex:- X2 , PI , Sigma
- Variable
It is an identifier or a name which is used to refer a value.
It is written with a combination of letters, numbers and special character with first letter being alphabet (Underscore & Dollar) also.
Ex:- C , fact , b33 , total_amount
- Data type
In javascript we do not have to specify type of variable.
“Var” can hold any type of data like string , number , boolean etc
Primitive data types:
Data Type | Description |
---|---|
String | represents sequence of characters e.g. “hello” |
Number | represents numeric values e.g. 100 |
Boolean | represents boolean value either false or true |
Undefined | represents undefined value |
Null | represents null i.e. no value at all |
Non-Primitive data types:
Data Type | Description |
---|---|
Object | represents instance through which we can access members |
Array | represents group of similar values |
RegExp | represents regular expression |
- Declaring Variable
var roll;
roll= name;
Here ‘roll’ is the variable name and ‘name’ is assigning value to variable.
If a variable is declared without a value then its value will be undefined.
Important points in Javascript:-
- Statements are executed one by one as they are written.
- Javascripts program and statements are often called Javascripts code.
- Semicolons separates javascript statements.
- Ending statement with semicolon is not required but it is highly recommended.
- Javascript ignores multiple spaces.
- Laravel 5.8 CRUD operation with example - April 22, 2021
- How to Create Multiple Role Based Authentication in Laravel 5.8 - April 16, 2021
- SQL Queries - April 5, 2021