Javascript Creating Arrays

The best way to create a new array is with the array literal syntax ([]),
but the array constructor function is available too. If you pass a single
number value to the constructor function, you get an array fi lled with
that many undefi ned values.
var myArray = [];
var myFilledArray = new Array(4);
myFilledArray;
[undefi ned, undefi ned, undefi ned, undefi ned]
Properties
Like strings, arrays have one built-in property: length. This property is
equal to the number greater than the last index in the array. This is true
even if you skip some indices.
["a", 1, true, null].length;
4
var myArray = [];
myArray.length;
0
myArray[99] = 1;
1
myArray.length;
100
The new length of myArray is 100 even though it contains only one value
at index 99. All the other values are undefined.

JavaScript String Length

The length  returns the number of characters that are in a string, using
an integer.


<script type="text/javascript">
var testString = "11111";
var length = testString.length;
document.write("The string length is: " + length);

</script>



output:-

The string length is: 5

Comparing strings in JavaScript


<script type="text/javascript">
var username = "test";
if(username == "test")
    document.write("Welcome");
else
    document.write("Access Denied!");
document.write("<br /><br />Try again?<br /><br />");


</script>

While '14' == 14 is true (because by converting either the left side
value to a number or converting the right side value to a text string
will result in both being the same) '123' === 123 is false since one
value is a text string and the other is a number.

The === operator does the same thing with one minor difference. This
operator does not convert data from one type to another.

JavaScript String indexOf

var p = navigator.platform;
system.win = p.indexOf(“Win”) == 0;
system.mac = p.indexOf(“Mac”) == 0;
system.x11 = (p.indexOf(“X11”) == 0) || (p.indexOf(“Linux”) == 0);


This code uses the indexOf() method to look at the beginning of the platform string. To detect
Windows, the platform-detection code simply looks for the string “Win” at the beginning of the
platform string (covers both “Win32” and “Win64”). Testing for a Mac platform is done in the same
way to accommodate both “MacPPC” and “MacIntel”. The test for Unix looks for both “X11” and
“Linux” at the beginning of the platform string to future-proof this code against other variants.

<script type="text/javascript">
var mURL = "http://www.google.com/";
var mPosition = mURL.indexOf("www");

document.write("The position of www  =  " + mPosition); 
</script>

Why Use Sitemaps?

It is important to use Sitemaps because they help your visitors quickly get to the information
they need, and they help web spiders find your site’s links.
There is no universal Sitemap rule that you can apply to every site. Understanding
different Sitemap options should help you identify the right type for each situation. The
following subsections discuss some of the reasons for using Sitemaps.

Crawl augmentation
Although web spiders are continuously improving, they are far from perfect. Search
engines have no problems admitting this.

Poor linking site structure
Not all sites are created equal. Sites with poor linking structures tend to index poorly.
Orphan pages, deep links, and search engine traps are culprits of poor site indexing.
The use of Sitemaps can alleviate these situations, at least temporarily, to give you
enough time to fix the root of the problem.

Crawling frequency
One of the biggest benefits of using Sitemaps is in timely crawls or recrawls of your site
(or just specific pages). XML Sitemap documents let you tell crawlers how often they
should read each page.
Sites using Sitemaps tend to be crawled faster on Yahoo! and Google. It takes Google
and Yahoo! minutes to respond to Sitemap submissions or resubmissions. This can be
very helpful for news sites, e-commerce sites, blogs, and any other sites that are constantly
updating or adding new content.

AdSense Earnings

The Google ads you are able to display on your content pages can be either cost-per-click
(CPC) or cost-per-1000-impressions (CPM) ads, while AdSense for search results pages
show exclusively CPC ads. This means that advertisers pay either when users click on
ads, or when the advertiser’s ad is shown on your site. You’ll receive a portion of the
amount paid for either activity on your website. Although we don’t disclose the exact
revenue share, our goal is to enable publishers to make as much or more than they could
with other advertising networks.

Typically, Google sends checks about one month behind if your earnings pass Google’s
payment threshold ($10 in the United States). You are responsible for paying any taxes
as required in your country. Let’s look at example earnings you can make with AdSense.
Suppose you have a site that shows 1,000 AdSense impressions per day. Assuming that
your CTR is at 1% and that the average click worth is $0.10, we get the following:
Daily AdSense Earnings =
1000 (impressions) × 0.01 (CTR) × 0.10 (click worth)
= $1

So, if you have a busy site, you can do the math and see what you can earn. It sounds
pretty simple, but to make it work you need to put in the time to create good content.
A lot depends on your visitor levels as well as how you integrate AdSense within your
site(s).

Competitor Research and Analysis

Competitor research and analysis may seem like a copycat activity, but it is not (at least
not entirely). It is about understanding what your competitors are doing. It is about
examining their keyword and linking strategies while realizing their current strengths
and weaknesses. The bottom line is that you are trying to understand what is making
your competitors rank.
This activity may comprise elements of emulation, but what you are really trying to do
is be better than your competition. Being better (in a general sense) means providing a
site with more value and better perception. In an SEO sense, it means understanding
all the things that make your competitors rank.
When learning about your competition, it is good to examine their past and present
activities, as well as implement ways to track their future activities. Although many
tools are available for you to use to learn about your competition, for most of your work
you can get by with the free tools that are available. This chapter emphasizes the free
tools and research that you can use in your work.

Finding Your Competition
Before you can analyze your competitors, you need to know who your competitors are.
How do you find your biggest competitors? One way to do this is to find sites that rank
for your targeted keywords. The sites that sell or provide products and services similar
to yours are your competitors.
There is a catch if you’re relying only on keywords, though. How do you know whether
you are targeting the right keywords? What if you miss important keywords? You may
be starting off in the wrong direction. This makes it all the more important to do your
keyword research properly. No tool or activity will ever be perfect. You have to start
somewhere.

Link Building

There are countless opportunities for link building. Everything starts on your site. Your
site should make it easy and intuitive for anyone wanting to link to it. To increase your
chances of people linking to your site, you need to provide something of value.
Basic Elements
The following subsections talk about the rudimentary elements that all sites need to
consider.
Take out the guesswork
Take out the guesswork for your web visitors by providing the HTML code fragment(s)
for people to link to your site. Create “Link to Us” and “Tell a Friend” links. Most CMS
software includes prebuilt forms for handling these simple concepts.

Run a daily, weekly, or monthly email newsletter
Running your own newsletter provides several benefits. First, you get to remind your
existing visitors of your new offerings, whether it is content, products, or services. Plus,
the recipients of your newsletter are likely to forward it to people they know if they find
your newsletter interesting.

Provide registered services
Many sites offer free and members-only content. This model offers several benefits. If
your free content is already great, many of your visitors will also be interested in your
members-only content. The idea is that the content that is provided to members only
is of even greater quality than the public content. Many sites charge for members-only
content. Providing registered services helps you build up the email lists that you can

JavaScript getElementById

getElementById() is a method of document object, it gets the tag element with the value "id" in its ID attribute.

To reference in a JS script to a HTML tag through its ID, use the following syntax:

    document.getElementById("id")

So even though the Internet Explorer JavaScript engine uses a mark-and-sweep
implementation, any COM objects that are accessed in JavaScript still use reference counting,
meaning circular references are still a problem when COM objects are involved. The following
simple example demonstrates a circular reference with a COM object:

var element = document.getElementById(“some_element”);
var myObject = new Object();
myObject.element = element;
element.someObject = myObject;

This example sets up a circular reference between a DOM element (element) and a native JavaScript
object (myObject). The myObject variable has a property called element that points to element,
and the element variable has a property called someObject that points back to myObject. Because
of this circular reference, the memory for the DOM element will never be reclaimed even if it is
removed from the page.

<script type="text/javascript">
function testEmpty(){
 var myTextField = document.getElementById('myTxt');
 if(myTxtField.value != "")
  alert("entered: " + myTxtField.value)
 else
  alert("please enter some text?")  
}
</script>
<input type='text' id='myTxt' />
<input type='button' onclick='testEmpty()' value='Checked' />

The argument that getElementById requires is the id of the HTML element you wish to utilize.

JavaScript Objects

Each Object instance has the following properties and methods:
constructor — The function that was used to create the object. In the previous example,
the constructor is the Object() function.

hasOwnProperty(propertyName) — Indicates if the given property exists on the object
instance (not on the prototype). The property name must be specifi ed as a string (for
example, dataObj.hasOwnProperty(“name”)).

isPrototypeOf(object) — Determines if the object is a prototype of another object.

propertyIsEnumerable(propertyName) — Indicates if the given property can be
enumerated using the for-in statement . As with
hasOwnProperty(), the property name must be a string.

toLocaleString() — Returns a string representation of the object that is appropriate for
the locale of execution environment.

toString() — Returns a string representation of the object.

valueOf() — Returns a string, number, or Boolean equivalent of the object. It often
returns the same value as toString().


A new instance of an object:

dataObj=new Object();

dataObj.firstname="Jonti";
dataObj.lastname="Leff";
dataObj.age=40;
dataObj.eyecolor="red";