Showing posts with label Electronics. Show all posts
Showing posts with label Electronics. Show all posts

Wednesday, September 25, 2013

JavaScript: Functions

JavaScript Functions

A function is a group of reusable code which can be called anywhere in your programme. This eliminates the need of writing same code again and again. Functions help programmers to write modular code. We can divide our programme into a number of small and manageable functions. Like any other advance programming language, JavaScript also supports all the features necessary to write modular code using functions.
Functions that are provided by JavaScript are called built-in functions and those defined by the user are called user-defined functions. alert(), confirm() etc. are examples for built-in functions.

Function Definition
Before we use a function we need to define that function. A function is defined as a code block (inside curly { } braces), preceded by the function keyword and name of the function.
A function can receive a list of values on which it can operate, known as the parameters of the function.
 The basic syntax is:
<script type="javascript">
      function functionname(parameter-list){
                              statements
      }
</script>
Example:
<script type="javascript">
      function helloWorld(){
                              alert("Hello World");
      }
</script>

Calling a Function
The function can be called directly when an event occurs (like when a user clicks a button), and it can be called from anywhere by JavaScript code.
To invoke a function we should simply write the name of that function as follows:
<script type="javascript">
      helloWorld();
</script>

Function Parameters
JavaScript allows the programmers to pass different parameters while calling a function.
These passed parameters can be captured inside the function and any manipulation can be done over them.
A function takes multiple parameters specified as a comma separated list.
<script type="javascript">
      function sayHello(name){
                              alert( "Hello "+name);
      }
</script>
Example:
<script type="javascript">
      sayHello("Vinod");
</script>
When the function is called as shown, it displays an alert dialog box with message 'Hello Vinod'.

Returning values
A JavaScript function can have an optional return statement. This is required if we want to return a value from a function. This statement should be the last statement in a function.
For example we can pass two numbers as parameters to function sum() and we can expect the function to return their sum to the point where it is called.
<script type="javascript">
      function sum(x, y){
                              var s;
                              s = x + y;
                              return  s;
      }
</script>
Now we can call this function as follows:
<script type="javascript">
      var result;
      result = sum(8, 6);
      alert("Sum:"+result );
</script>
The output of the above code will be an alert dialog box displaying 'Sum:14'
Scope of Variables
With respect to their scope variables can be classified into two as local variables and global variables.
A variable declared within a JavaScript function becomes local variable and can only be accessed from within that function. It is said to have local scope. We can have local variables with the same name in different functions, because local variables are only recognized by the function in which they are declared. Local variables are deleted as soon as the function is completed.
Variables declared outside a function, become global variable, and all scripts and functions on the web page can access it. They are deleted only when the page closes
Example:
<script  type="javascript">
      var x;
      function sum(a,b){
                              x=a+b
      }
      function displaySum(){
                              alert("Sum:"+x)
      }
</script>
In the above example x is a global variable while a and b are local to the function sum(). So x can be easily accessed by the function displaySum() which displays the sum calculated in sum().

Tuesday, September 24, 2013

Microsoft FrontPage

Microsoft FrontPage

Introduction
Microsoft FrontPage (full name Microsoft Office FrontPage) is a WYSIWYG(What-You-See-Is-What-You-Get) HTML editor and web site administration tool from Microsoft. It was a part of the Microsoft Office suite from 1997 to 2003. It has since been replaced by Microsoft Expression Web and Sharepoint Designer, which were first released in December 2006 alongside Microsoft Office 2007. FrontPage was initially created by the Cambridge, Massachusetts company Vermeer Technologies Incorporated. Vermeer was acquired by Microsoft in January 1996.
As a WYSIWYG editor, FrontPage is designed to hide the details of pages' HTML code from the user, making it possible for novices to easily create web pages and sites.
In 2006, Microsoft announced that FrontPage would eventually be superseded by two products. Microsoft SharePoint Designer will allow business professionals to design SharePoint-based applications. Microsoft Expression Web is targeted at the web design professional for the creation of feature-rich web sites. Microsoft announced that FrontPage will be discontinued from December 2006.

Advantages
  1. FrontPage 2003 consists of a Split View option to allow the user to code in Code View and preview in Design View without the hassle of switching from the Design and Code View tabs for each review
  2. Dynamic Web Templates (DWT) allows the users to create a single template that could be used across multiple pages and even the whole Web site
  3. Interactive Buttons give users a new easy way to create web graphics for navigation and links, eliminating the need for a complicated image-editing package such as Adobe Photoshop
  4. The accessibility checker gives user the ability to check if their code is standards compliant and that their Web site is easily accessible for people with disabilities. An HTML optimizer is included to aid in optimizing code to make it legible and quicker to process
  5. Intellisense, which is a form of auto completion, is a key feature that assists the user while typing in Code View. When working in Code View, Intellisense will suggest tags and/or properties for the code that the user is entering which significantly reduces the time to write code. 
  6. Code Snippets give users the advantage to create snippets of their commonly used pieces of code allowing them to store it for easy access whenever it is next needed
  7. FrontPage includes support for programming in ASP.NET, a server-side scripting language, that adds interactivity to Web sites and Web pages
  8. FrontPage includes support for macros in Visual Basic.


Tuesday, September 17, 2013

Web Fundamentals

History of the Internet


The invention of the telegraph, telephone, radio, and computer set the stage for the unprecedented revolution of communication. The Internet is at once a world-wide broadcasting capability. The Internet today is a widespread information infrastructure, the initial prototype of what is often called the National (or Global or Galactic) Information Infrastructure. Its history is complex and involves many aspects - technological, organizational, and community. And its influence reaches not only to the technical fields of computer communications but throughout society.
The first recorded description of the social interactions that could be enabled through networking was a series of memos written by J.C.R. Licklider of MIT in August 1962 discussing his "Galactic Network" concept. He envisioned a globally interconnected set of computers through which everyone could quickly access data and programs from any site.  Licklider was the first head of the computer research program at DARPA, starting in October 1962. The public was first introduced to the concepts that would lead to the Internet when a message was sent over the ARPANet from computer science Professor Leonard Kleinrock's laboratory at University of California, after the second piece of network equipment was installed at Stanford Research Institute (SRI). By the end of 1969, four host computers were connected together into the initial ARPANET, and the budding Internet was off the ground.
Computers were added quickly to the ARPANET during the following years, and work proceeded on completing a functionally complete Host-to-Host protocol and other network software. Packet switched networks such as ARPANET were developed in the late 1960s and early 1970s using a variety of protocols. The ARPANET in particular led to the development of protocols for internetworking, in which multiple separate networks could be joined together into a network of networks.
In 1982, the Internet protocol suite (TCP/IP) was standardized, and consequently, the concept of a world-wide network of interconnected TCP/IP networks, called the Internet, was introduced. Access to the ARPANET was expanded in 1981 when the National Science Foundation (NSF) developed the Computer Science Network (CSNET) and again in 1986 when NSFNET provided access to supercomputer sites in the United States from research and education organizations. Commercial Internet service providers (ISPs) began to emerge in the late 1980s and early 1990s. The ARPANET was decommissioned in 1990. The Internet was commercialized in 1995 when NSFNET was decommissioned, removing the last restrictions on the use of the Internet to carry commercial traffic.
Since the mid-1990s, the Internet has had a revolutionary impact on culture and commerce, including the rise of near-instant communication by electronic mail, instant messaging, Voice over Internet Protocol (VoIP) "phone calls", two-way interactive video calls, and the World Wide Web with its discussion forums, blogs, social networking, and online shopping sites. The research and education community continues to develop and use advanced networks such as NSF's very high speed Backbone Network Service (vBNS), Internet2, and National LambdaRail. Increasing amounts of data are transmitted at higher and higher speeds over fibre optic networks operating at 1-Gbit/s, 10-Gbit/s, or more. The Internet's takeover over the global communication landscape was almost instant in historical terms: it only communicated 1% of the information flowing through two-way telecommunications networks in the year 1993, already 51% by 2000, and more than 97% of the telecommunicated information by 2007. Today the Internet continues to grow, driven by ever greater amounts of online information, commerce, entertainment, and social networking.

Basic Services
Some of the basic services available to Internet users are:
  • Email: A fast, easy, and inexpensive way to communicate with other Internet users around the world.
  • Telnet: Allows a user to log into a remote computer as though it were a local system.
  • FTP: Allows a user to transfer virtually every kind of file that can be stored on a computer from one Internet-connected computer to another.
  • Usenetnews: A distributed bulletin board that offers a combination news and discussion service on thousands of topics.
  • World Wide Web (WWW): A hypertext interface to Internet information resources.
  • Social Networking
  • E Commerce
  • Online examinations
Search engines
Search engines are the primary tools people use to find information on the web. Today, you perform searches with keywords, but the future of web search will use natural language. Currently, when you enter a keyword or phrase, the search engine finds matching web pages and show you a search engine results page (SERP) with recommended web pages listed and sorted by relevance. People-assisted search engines have also emerged, such as Mahalo, which pays people to develop search results.
A search engine operates in the following order:
  • Web crawling
  • Indexing
  • Searching
Web search engines work by storing information about many web pages, which they retrieve from the page's HTML. These pages are retrieved by a Web crawler (sometimes also known as a spider) — an automated Web browser which follows every link on the site. The contents of each page are then analysed to determine how it should be indexed (for example, words can be extracted from the titles, page content, headings, or special fields called meta tags).
Data about web pages are stored in an index database for use in later queries. The index helps find information relating to the query as quickly as possible. When a user enters a query into a search engine (typically by using keywords), the engine examines its index and provides a listing of best-matching web pages according to its criteria, usually with a short summary containing the document's title and sometimes parts of the text.
Currently Google is the leading search engine followed by Yahoo and Microsoft.

Google Search
Google is the leading search and online advertising company, founded by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University. Google’s success in search is largely based on its PageRank algorithm (patented by Larry Page) and its unique infrastructure of servers that uses linked PCs to achieve faster responses and increased scalability at lower costs. Estimates on the number of Google servers range over one million.
The PageRank algorithm considers the number of links into a web page and the quality of the linking sites (among other factors) to determine the importance of the page.
In addition to its regular search engine, Google offers speciality search engines for images, news, videos, blogs and more.

Vertical search engines
Vertical search engines are specialists (focusing on specific topics) in comparison to generalists like Google and Yahoo. They enable us to search for resources in a specific area, with the goal of providing you with a smaller number of more relevant results.

Location-based search

Location-based search (offered by most major search engines as well as some smaller specialized ones) uses geographic information about the searcher to provide more relevant search results. For example, search engines can ask the user for a ZIP code or estimate the user’s general location based on IP address. The engine can then use this information to give higher priority to search results physically located near the user. This is particularly useful when searching for businesses such as restaurants or car services.

e-mail
One of the most popular Internet services is electronic mail (e-mail). At the beginning of the Internet era, the messages sent by electronic mail were short and consisted of text only; they let people exchange quick memos. Today, electronic mail is much more complex. It allows a message to include text, audio, and video. It also allows one message to be sent to one or more recipients.
An e-mail system has three main components: user agent, message transfer agent, and message access agent.
User Agent: It provides service to the user to make the process of sending and receiving a message easier. A user agent is a software package (program) that composes, reads, replies to, and forwards messages. It also handles mailboxes.
Message Transfer Agent: The actual mail transfer is done through message transfer agents. The process of transferring a mail message occurs in three phases: connection establishment, mail transfer, and connection termination. It uses SMTP protocol.
Message Access Agent: Mail access starts with the client when the user needs to download e-mail from the mailbox on the mail server. The client opens a connection to the server on TCP port. It then sends its user name and password to access the mailbox. The user can then list and retrieve the mail messages, one by one. it uses protocols like POP3, IMAP etc.
Web-Based Mail
E-mail is such a common application that some websites today provide this service to anyone who accesses the site. Two common sites are Gmail, Hotmail and Yahoo. Mail transfer from browser to mail server is done through HTTP.

WWW
The World Wide Web (abbreviated as WWW or W3, commonly known as the web) is a system of interlinked hypertext documents accessed via the Internet. A broader definition comes from the organization that Web inventor Tim Berners-Lee helped found, the World Wide Web Consortium (W3C):
The World Wide Web is the universe of network-accessible information, an embodiment of human knowledge.
The WWW project was initiated by CERN (European Laboratory for Particle Physics) to create a system to handle distributed resources necessary for scientific research.
The WWW today is a distributed client-server service, in which a client using a browser can access a service using a server. However, the service provided is distributed over many locations called sites. Each site holds one or more documents, referred to as Web pages. Each Web page can contain a link to other pages in the same site or at other sites. The pages can be retrieved and viewed by using browsers.
In simple terms, The World Wide Web is a way of exchanging information between computers on the Internet, tying them together into a vast collection of interactive multimedia resources.

Web Server
Web servers is a specialized software that responds to client requests (typically from a web browser) by providing resources such as HTML/XHTML documents. For example, when users enter a Uniform Resource Locator (URL) address, such as graduatingcs.blogspot.in, into a web browser, they are requesting a specific document from a web server. The web server maps the URL to a resource on the server (or to a file on the server’s network) and returns the requested resource to the client. During this interaction, the web server and the client communicate using the platform-independent Hypertext Transfer Protocol (HTTP), a protocol for transferring requests and files over the Internet.
Multitier Application Architecture
Web-based applications are multitier applications that divide functionality into separate tiers (i.e., logical groupings of functionality). Although tiers can be located on the same computer, the tiers of web-based applications often reside on separate computers. Figure presents the basic structure of a three-tier web-based application.
3 Tier Architecture
The bottom tier (also called the data tier or the information tier) maintains the application’s data. This tier typically stores data in a relational database management system (RDBMS). They may reside on one or more computers.
The middle tier implements business logic, controller logic and presentation logic to control interactions between the application’s clients and its data. The middle tier acts as an intermediary between data in the information tier and the application’s clients. The middle-tier controller logic processes client requests and retrieves data from the database. The middle-tier presentation logic then processes data from the information tier and presents the content to the client. Web applications typically present data to clients as XHTML documents.
Business logic in the middle tier enforces business rules and ensures that data is reliable before the application updates a database or presents data to users. Business rules dictate how clients access data, and how applications process data. For example, a business rule in the middle tier of a retail store’s web-based application might ensure that all product quantities remain positive. A client request to set a negative quantity in the bottom tier’s product information database would be rejected by the middle tier’s business logic.

The top tier, or client tier, is the application’s user interface, which gathers input and displays output. Users interact directly with the application through the user interface, which is typically a web browser, keyboard and mouse, or a mobile device. In response to user actions (e.g., clicking a hyperlink), the client tier interacts with the middle tier to make requests and to retrieve data from the information tier. The client tier then displays the data retrieved for the user. The client tier never directly interacts with the information tier.

The Apache HTTP Server
The Apache HTTP Server, commonly referred to as Apache, is a web server software program playing a key role in the growth of the World Wide Web. Apache has consistently been the most popular web server on the Internet since 1996. Typically Apache is run on a Unix-like operating system, and was developed for use on Linux.
Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation. The application is available for a wide variety of operating systems, including Unix, Linux, Solaris, Novell NetWare, Microsoft Windows etc. Released under the Apache License, Apache is open-source software.
Since April 1996 Apache has been the most popular HTTP server software in use. As of June 2013, Apache was estimated to serve 54% of all active websites.
Apache supports a variety of features, many implemented as compiled modules which extend the core functionality.  These can range from server-side programming language support to authentication schemes like password authentication. It also features configurable error messages. Some common language interfaces supported are Perl, Python and PHP.

Internet Information Services (IIS)
Internet Information Services (IIS) – formerly called Internet Information Server – is a Microsoft web server software application created by Microsoft for use with Microsoft Windows. IIS 7.5 supports HTTP, HTTPS, FTP, FTPS, SMTP and NNTP. It is part of certain editions of Windows XP, Windows Vista and Windows 7. IIS is not turned on by default. The IIS Manager is accessed through the Administrative Tools in the Control Panel.
All versions of IIS prior to 7.0 running on client operating systems supported only 10 simultaneous connections and a single web site.
With IIS 8 you can share information with users on the Internet, an intranet, or an extranet. IIS 8 is a unified web platform that integrates IIS, ASP.NET, FTP services, PHP, and Windows Communication Foundation (WCF).

IIS is the second most popular web server in the world with 20% market share.

Protocols
In computer networks, communication occurs between entities in different systems. An entity is anything capable of sending or receiving information. However, two entities cannot simply send bit streams to each other and expect to be understood. For communication to occur, the entities must agree on a protocol. A protocol is a set of rules that govern data communications. A protocol defines what is communicated, how it is communicated, and when it is communicated.

The key elements of a protocol are syntax, semantics, and timing.


  • Syntax: The term syntax refers to the structure or format of the data, meaning the order in which they are presented.
  • Semantics: The word semantics refers to the meaning of each section of bits. How is a particular pattern to be interpreted, and what action is to be taken based on that interpretation?
  • Timing: The term timing refers to two characteristics: when data should be sent and how fast they can be sent.

Hyper Text Transfer Protocol (HTTP)
The Hypertext Transfer Protocol (HTTP) is a protocol used mainly to access data on the World Wide Web. HTTP functions as a combination of FTP and SMTP. The client initializes the transaction by sending a request message. The server replies by sending a response. A request message consists of a request line, a header, and sometimes a body. A response message consists of a status line, a header, and sometimes a body.

File Transfer Protocol (FTP)
File Transfer Protocol (FTP) is the standard mechanism provided by TCP/IP for copying a file from one host to another. Transferring files from one system to another need to deal with some problems. For example, two systems may use different file name conventions. Two systems may have different ways to represent text and data. Two systems may have different directory structures. All these problems have been solved by FTP in a very simple and elegant approach.
FTP differs from other client/server applications in that it establishes two connections between the hosts. One connection is used for data transfer, the other for control information (commands and responses). Separation of commands and data transfer makes FTP more efficient.
We need to transfer only a line of command or a line of response at a time. The data connection, on the other hand, needs more complex rules due to the variety of data types transferred.
The control connection remains connected during the entire interactive FTP session. The data connection is opened and then closed for each file transferred. It opens each time commands that involve transferring files are used, and it closes when the file is transferred.

TELNET
In the Internet, users may want to run application programs at a remote site and create results that can be transferred to their local site. For example, students may want to connect to their university computer lab from their home to access application programs for doing homework assignments or projects.
TELNET is general-purpose client-server program that lets a user access any application program on a remote computer; in other words, allow the user to log on to a remote computer. After logging on, a user can use the services available on the remote computer and transfer the results back to the local computer.
TELNET is an abbreviation for TErminaL NETwork. TELNET enables the establishment of a connection to a remote system in such a way that the local terminal appears to be a terminal at the remote system.
When a user wants to access an application program or utility located on a remote machine, he performs remote log-in using a user-name and password. TELNET uses only one TCP connection. The same connection is used for sending both data and control characters. TELNET accomplishes this by embedding the control characters in the data stream.
Most TELNET implementations operate in one of three modes: default mode, character mode, or line mode.
  • Default Mode: The default mode is used if no other modes are invoked through option negotiation. In this mode, the echoing is done by the client. The user types a character, and the client echoes the character on the screen (or printer) but does not send it until a whole line is completed.
  • Character Mode: In the character mode, each character typed is sent by the client to the server. The server normally echoes the character back to be displayed on the client screen.
  • Line Mode: A new mode has been proposed to compensate for the deficiencies of the default mode and the character mode. In this mode, called the line mode, line editing (echoing, character erasing, line erasing, and so on) is done by the client. The client then sends the whole line to the server.

Monday, August 19, 2013

Java Script:Dialog Boxes and Prompts

Dialog Boxes and Prompts

Dialog boxes are used to raise an alert, or to get confirmation on any action or to take small amount of input from the users. JavaScript supports three important types of dialog boxes: The alert, confirm and prompt dialog boxes. These dialog boxes appear as separate windows and their content is independent from the text in html page and does not affect the content of the page. The three types of dialog boxes provided by JavaScript are:

Alert Dialog Box:
An alert dialog box is mostly used to give a warning message to the users. Like if one input field requires to enter some text but user does not enter that field then as a part of validation you can use alert box to give warning message. An alert dialog box is invoked using the alert() method, which takes a string as argument and displays it in the dialog box. In addition to the string, it also displays an OK button. Once the dialog box is displayed, the JavaScript and HTML code stops processing until the OK button is pressed.
Syntax:
alert(“<Message>”);
Example:
alert(“Welcome to my Webpage”);

Prompt Dialog Box:
The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus it enables you to interact with the user. The prompt() method instantiates the prompt dialog box. It displays a specified message and also provides a single data entry field, which accepts the user input.
The prompt() method takes two parameters (i) A label which you want to display in the text box (ii) A default string to display in the text box.
Syntax:
prompt(“<Message>”, “<Default text>”);
Example:
prompt(“Enter your favourite colour”, “Red”);
Prompt dialog box has two buttons: OK and Cancel. If the user clicks on OK button the prompt() will return entered value from the text box. If the user clicks on the Cancel prompt() returns null.
You can use prompt dialog box as follows:

Confirmation Dialog Box:
A confirmation dialog box is mostly used to take user's consent on any action. The confirm() method displays a dialog box with a predefined message and two buttons: OK and Cancel.
Syntax:
confirm(“<Message>”);
Example:
confirm(“Are you sure you want to quit?”);
If the user clicks on OK button the window method confirm() will return true. If the user clicks on the Cancel button confirm() returns false.

Wednesday, July 17, 2013

Java Script - Basics

Introduction

Today’s websites need to go much beyond HTML. There is a definite need to allow users, browsing through a website to interact with the website. The website must be intelligent to accept user’s input and dynamically structure the contents of the webpage according to the input. This requires a website development environment that will allow the creation interactive of web pages.
Capturing user requests is traditionally done through a form. After a form captures user input, the form must have built-in technique for sending the information captured back to the web server for processing. The captured input need to be validated before sending it to the server. Hence the development environment must facilitate coding which runs in a browser at client side for data validation.
JavaScript allows us to add such capabilities to a webpage.
JavaScript is a scripting language introduced by Netscape. JavaScript made its first appearance in Netscape 2.0 in 1995 with a name LiveScript.
JavaScript is the world's most popular programming language. It is the language for HTML and the web. JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. JavaScript is programming code that can be inserted into HTML pages.

Advantages
Some of the other advantages of JavaScript are:
·        An Interpreted language: JavaScript is an interpreted language. So it does not require any compilation steps.
·        Quick Development: JavaScript does not require any special or separate editor. It also does not require time consuming compilation steps. This facilitates fast development.
·        Designed for simple small programs: It is well suited to implement simple, small programs (Eg: a unit conversion). Such programs can be written and executed at acceptable speeds.
·        Performance: JavaScript can be written in such a way that HTML pages are compact and small. As it is embedded in the HTML code, there is no need of additional network access to retrieve the page.
·        Procedural capabilities: JavaScript has capabilities of any programming language like condition checking, looping and branching.
·        Designed for programming user events: JavaScript supports event based programming. That is it can detect when an user event occurs (Eg: A button being pressed) and respond accordingly.
·        Easy Debugging and testing: Being an interpreted language, scripts in JavaScript are tested line by line and the errors are also listed as they are encountered. So its easy to locate errors.
·        Platform independence / Architecture neutral: JavaScript is completely independent of the hardware on which it works. Browsers are platform specific. They take care of implementing JavaScript according to the platform. This relieves the user of maintaining multiple source code files.

JavaScript Syntax
A JavaScript consists of JavaScript statements that are placed within the <script>... </script> HTML tags in a web page.
You can place the <script> tag containing your JavaScript within the <head> or <body> of you web page, but it is preferred way to keep it within the <head> tags.
The <script> tag alert the browser program to begin interpreting all the text between these tags as a script. So simple syntax of your JavaScript will be as follows
<script >
              JavaScript code
</script>
The script tag takes one important attribute language. This attribute specifies what scripting language is being used. Typically, its value will be javascript.
So your JavaScript segment will look like:
<script language="javascript">
                           JavaScript code
</script>

Data Types
One of the most fundamental characteristics of a programming language is the set of data types it supports. These are the type of values that can be represented and manipulated in a programming language.
JavaScript allows you to work with three primitive data types:
·        Number: It defines all integer and floating point numbers and a special number NaN (Not a Number). Integers can be represented in Decimal, Octal and Hexadecimal format.
e.g. 123, 120.50 etc.
·        String: It defines all strings that are enclosed in single (‘ ’) or double (“ ”) quotes.
e.g. "This text string", ‘Krishna’ etc.
·        Boolean: Defines logical values true and false. JavaScript automatically converts true into 1 and false into 0 when used in numerical expressions.
·        Null: Defines only a single value null which identifies null, empty or non-existent reference.
JavaScript does not make a distinction between integer values and floating-point values. All numbers in JavaScript are represented as floating-point values. JavaScript represents numbers using the 64-bit floating-point format.

Variables
Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.
Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows:
            <script language="javascript">
                                    var money;
                                    var name;
            </script>
Storing a value in a variable is called variable initialization. You can do variable initialization at the time of variable creation or later point in time when you need that variable as follows:
            <script language ="javascript">
                                    var name = "Ram";
                                    var money;
                                    money = 2000.50;
            </script>
JavaScript is untyped language. This means that a JavaScript variable can hold a value of any data type. Unlike many other languages, you don't have to tell JavaScript during variable declaration what type of value the variable will hold. The value type of a variable can change during the execution of a program and JavaScript takes care of it automatically.
Arrays
Arrays are JavaScript objects capable of holding a sequence of values. These values are stored in contiguous memory locations and accessed by the name of the array followed by the index. An array can be declared as below
            arrayName = new Array(length);
If an array is created without specifying the size, JavaScript creates an array of size zero and automatically extends the length of the array when elements are added.
            Eg: students = new Array();
Arrays are extendable even if the length is specified initially.
Dense Arrays
A dense array is an array that has been created with each of its element being assigned a specific value. They are declared and initialised at the same time.

Operators
JavaScript language supports following type of operators.
·        Arithmetic Operators
·        Assignment Operators
·        Comparison Operators
·        Logical Operators
·        The Conditional (or ternary) Operator
·        Bitwise Operators
·        Special Operators
Let us have a look on all operators one by one.

The Arithmetic Operators
There are following arithmetic operators supported by JavaScript language:

Assume variable A holds 10 and variable B holds 20 then:

Operator
Description
Example
+
Adds two operands
A + B will give 30
-
Subtracts second operand from the first
A - B will give -10
*
Multiply both operands
A * B will give 200
/
Divide numerator by denominator
B / A will give 2
%
Modulus Operator and remainder of after an integer division
B % A will give 0
++
Increment operator, increases integer value by one
A++ will give 11
--
Decrement operator, decreases integer value by one
A-- will give 9
Note: Addition operator (+) works for Numeric as well as Strings. e.g. "a" + 10 will give "a10".

The Assignment Operators
There are following assignment operators supported by JavaScript language:
Operator
Description
Example
=
Simple assignment operator, Assigns values from right side operands to left side operand
C = A + B will assign value of A + B into C
+=
Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
C += A is equivalent to C = C + A
-=
Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand
C -= A is equivalent to C = C - A
*=
Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand
C *= A is equivalent to C = C * A
/=
Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand
C /= A is equivalent to C = C / A
%=
Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand
C %= A is equivalent to C = C % A

The Comparison Operators
There are following comparison operators supported by JavaScript language
Assume variable A holds 10 and variable B holds 20 then:
Operator
Description
Example
==
Checks if the values of two operands are equal or not, if yes then condition becomes true. Here the data type of the operands are not considered.
(A == B) is not true.
!=
Checks if the values of two operands are equal or not, if values are not equal then condition becomes true.
(A != B) is true.
> 
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.
(A > B) is not true.
< 
Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.
(A < B) is true.
>=
Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.
(A >= B) is not true.
<=
Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.
(A <= B) is true.
===
Strictly equal. Checks the data type of the operands also.
10 == “10” is true
10 === “10” is false
!==
Strictly not equal. Considers the data type of the operands also.
20 != “20”  is false
20 !== “20” is true.

The Logical Operators
There are following logical operators supported by JavaScript language
Assume variable A holds 10 and variable B holds 20 then:
Operator
Description
Example
&&
Called Logical AND operator. If both the operands are non zero then the condition becomes true.
(A && B) is true.
||
Called Logical OR Operator. If any of the two operands are non zero then the condition becomes true.
(A || B) is true.
!
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
!(A && B) is false.

The Conditional Operator (? :)

Conditional operator first evaluates an expression for a true or false value and then execute one of the two given statements depending upon the result of the evaluation.
The conditional operator has the syntax:
Operator
Description
Example
? :
If Condition is true ? Then value X : Otherwise value Y
k = (a==b) ? 10 : 2
k gets value 10 if a is equal to b and 2 if a is not equal to b

Bitwise Operators
There are following bitwise operators supported by JavaScript language
Assume variable A holds 2 and variable B holds 3 then:
Operator
Description
Example
&
Bitwise AND operator. It performs a Boolean AND operation on each bit of its integer arguments.
(A & B) is 2
|
Bitwise OR Operator. It performs a Boolean OR operation on each bit of its integer arguments.
(A | B) is 3
^
Bitwise XOR operator. It performs a Boolean exclusive OR operation on each bit of its integer arguments. Exclusive OR means that either operand one is true or operand two is true, but not both.
(A ^ B) is 1
~
Bitwise NOT operator. It is a unary operator and operates by reversing all bits in the operand.
(~B) is -4 .
<< 
Bitwise Shift Left operator. It moves the bits in its first operand to the left by the number of places specified in the second operand. New bits are filled with zeros. Shifting a value left by one position is equivalent to multiplying by 2, shifting two positions is equivalent to multiplying by 4, etc.
(A << 1) is 4.
>> 
Bitwise Shift Right with Sign operator. It moves the bits in its first operand to the right by the number of places specified in the second operand. The bits filled in on the left depend on the sign bit of the original operand, in order to preserve the sign of the result. Shifting a value right one place is equivalent to dividing by 2 (discarding the remainder).
(A >> 1) is 1.
>>> 
Bitwise Shift Right with Zero operator. This operator is just like the >> operator, except that the bits shifted in on the left are always zero (not the sign bit).
(A >>> 1) is 1.

Special operators
JavaScript supports some additional operators other than those given above
Operator
Description
Example
new
The new operator is used to create an instance of an object type.
myArray = new Array();
delete
To delete a property of an object or an element at an array index
delete myArray[5]
deletes 6th element of the array

Placing Text in a Browser
JavaScript uses the write() method of document object for placing text in a browser. Methods are called combining the object name with method name.
objectName.methodName
The write() method accepts a string value as argument, and places it in the current browser window.

Example: document.write(“Hello World”);

Conditional Statements
Conditional statements are used to perform different actions based on different conditions.
In JavaScript we have the following conditional statements:
  • if statement - use this statement to execute some code only if a specified condition is true
  • if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false
  • if...else if....else statement - use this statement to select one of many blocks of code to be executed
  • switch statement - use this statement to select one of many blocks of code to be executed
If Statement
Use the if statement to execute some code only if a specified condition is true.
Syntax
if (condition)
{
      code to be executed if condition is true
}
Example
if (a<10)
{
      a++;
}
Here the variable a gets incremented if its value is less than 10.
If...else Statement
Use the if....else statement to execute some code if a condition is true and another code if the condition is not true.
Syntax
if (condition)
{
      code to be executed if condition is true
}else
{
      code to be executed if condition is not true
}
Example
if (a<10){
      a++;
}else{
      b++;
}
Here the variable a gets incremented if its value is less than 10 and b gets incremented if the condition is false
Switch Statement
Use the switch statement to select one of many blocks of code to be executed.

Syntax

switch(n)
{
      case 1:
                   execute code block 1
                   break;
      case 2:
                   execute code block 2
                   break;
      default:
                   code to be executed if n is different from 1 and 2
}
We have a single expression n (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each case in the structure. If there is a match, the block of code associated with that case is executed. Use break to prevent the code from running into the next case automatically. Use the default keyword to specify what to do if there is no match:
Example
switch (day)
{
      case 0:
                   x="Today it's Sunday";
                   break;
      case 1:
                   x="Today it's Monday";
                   break;
      case 2:
                   x="Today it's Tuesday";
                   break;
      case 3:
                 x="Today it's Wednesday";
                 break;
      case 4:
                 x="Today it's Thursday";
                 break;
      case 5:
                 x="Today it's Friday";
                 break;
      case 6:
                 x="Today it's Saturday";
                 break;
      default:
                 x = "Invalid";
}
In the above example suppose day has a value 4, then x gets value ="Today it's Thursday". Suppose day is not in the range 0 to 6, then the default block is executed and x gets the value “Invalid”.

Loops
Loops can execute a block of code a number of times.
JavaScript supports different kinds of loops:
  •          for - loops through a block of code a number of times
  •          for/in - loops through the properties of an object
  •          while - loops through a block of code while a specified condition is true
  •          do/while - also loops through a block of code while a specified condition is true

The For Loop
The for loop is often the tool you will use when you want to create a loop.
The for loop has the following syntax:
for (statement 1; statement 2; statement 3)
{
       the code block to be executed
}
Statement 1 is executed before the loop (the code block) starts.
Statement 2 defines the condition for running the loop (the code block).
Statement 3 is executed each time after the loop (the code block) has been executed.
Example:
for (var i=0; i<5; i++)
{
      document.write("The number is " + i + "<br>");
}

The For/In Loop
The JavaScript for/in statement loops through the properties of an object:
var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
       txt=txt + person[x];
}

The While Loop
The while loop loops through a block of code as long as a specified condition is true.
Syntax:
while (condition)
{
      code block to be executed
}
Example:
while (i<5){
      document.write("The number is " + i + "<br>");
       i++;
}

The Do/While Loop
The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, and then it will repeat the loop as long as the condition is true.
Syntax
do
{
      code block to be executed
}while (condition);
Example:
do
{
      document.write(The number is " + i + "<br>");
      i++;
}while (i<5);