Basics Concepts of JavaScript
Java script is a client side scripting language and it is standardize by ECMA. Its code is written between opening <script> and closing </script> tags. By using JavaScript we can create dynamic web page. JavaScript is embedded within HTML.
<script> tag has "type" attribute you must need to add in scripts tag like.
<script type="text/javascript">
There are three ways to write JavaScript code in your web page.
In external way: there is src attribute like <script type="text/javascript" src="script.js(filepath)"> while in embedded we write JavaScript inside the html page enclosed in <script></script> tags.
Note: never use inline because you write this in html elements so very difficult to manage.
What are Client Side Languages?
Client side scripting languages are executed on any client machine instead of server so it doesn't take time to execute.
What are Server Side Languages?
Server-side scripting is used in web development which involves scripts on a web server which produces a response customized for each client's request to the website.
variable stores the value.
variable have some to define.
1. variable name can be letter, number, any symbols.
2. variable name can't start with numbers it must start with letter.
3. variable name is case sensitive. Var and var both are different name
var = X; var = x; (both are different)
4. reserved keywords can't be given as variable name.
like function, switch, return etc.
5. logical operator[=, +, -, /] cannot use in variable name.
6. blank space is not allowed within variable name.
The latest ECMAScript standard defines seven data types:
There are six primitive types of datatype.
it has two values true and false.
alert(a+'bhumi');//nullbhumi (concatenation)
variable has not assigned any value its undefined.
alert(a+'bhumi');//undefinedbhumi (concatenation)
variable has assigned by any number.
variable has assigned by any latter.
(new in ECMAScript 6). A data type whose instances are unique and immutable.
There are three types of pop ups.
it is used for pop up alert message has one button is 'ok'.
alert('welcome to my website');//message
it is used for conformation it has two button 'ok' and 'cancel'
confirm('Are you 18+');//ok and concel (Boolean = 0/1 or false/true)
it is used to get vales from user.
prompt( 'Enter your age plz');
A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when it call.
function function name(para1, para2)
<button onclick="main()">Click me</button>
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
function contains other function call nested function. Such functions are very useful for abstraction and encapsulation.
Two types of scope in function.
local variable can be use within the function. you cant use it out side the function.
global variable can use anywhere in the code.
Conditionals in JavaScript
-> Use if to specify a block of code to be executed, if a specified condition is true
-> Use else to specify a block of code to be executed, if the same condition is false
-> Use else if to specify a new condition to test, if the first condition is false
it has many alternative code to execute.
it has two values true and false
var result = (getName == 45)?'yes it is':'no it is not';
Loops are set of code which is used to repeat the condition of loop block. Loops returns the true or false values depend on the condition.
You can counter the loops by increments and decrements.
for (statement 1; statement 2; statement 3) {
code block to be executed
for (var i = 0; i < 10; i++) {
console.log(i);//0,1,2,3,4,5,6,7,8,9
When variable does not stored in array or variable have key pvalue pair then you can use for in loop.
code block to be executed
alert( myArr['name'] ); //Bhumi
console.log("At key "+i+" got "+myArr[i]+" value.");
This loop control the flow of code depend on condition. this loop checks the condition first and then it will do increments or decrements
code block to be executed
console.log(i); //0,1,2,3,4,5,6,7,8,9
This loop first do the increment or decrements and the it checks the condition. Control flow statement that executes a block of code at least once.
code block to be executed
console.log("before: "+i);//0,1,2,3,4,5,6,7,8,9
Source: http://admec-multimedia-institute.blogspot.in/2016/06/basics-concepts-of-javascript.html