Tuesday, February 21, 2012

SQL Server INDEXES

INDEXES:
    • Clustered indexes are usually faster than non-clustered indexes (one could come very close to saying always, but there are exceptions).
    • Only place non-clustered indexes on columns where you are going to get a high level of selectivity(that is, 95 percent or more of the rows are unique)
    • All DML statements (INSERT, DELETE, UPDATE) and SELECT statement can benefit from indexes, but insert, deletes, and updates (remember they use a delete and insert approach) are slowed by indexes. The lookup part of a query is helped by the index, but any thing modifies data will have extra work to do (to maintain the index in addition to the actual data).
    • Indexes take up space.
    • Indexes are used only if the first column in the index is relevant to your query.
    • Indexes can hurt as they help – know why you’re building the index, and don’t build indexes you don’t need.
    • Indexes can provide structured data performance to your unstructured XML data, but keep in mind that, like other indexes, there is overhead involved.
    • When you’re thinking about indexes, ask yourself, these questions:

Questions
Response
Are there a lot of inserts or modifications to this table?
If yes, keep indexes to a minimum. This kind of table usually has modifications done through single record lookups of the primary key – usually, this is the only index you want on the table. If the inserts are non-sequential, think about not having a clustered index.
Is this a reporting table? That is, not many insert, but reports run lots of different ways?
More indexes are fine. Target the clustered index to frequently used information that is likely to be extracted in ranges. OLAP installations will often have many times the number of indexes seen in an OLTP environment.
Is there a high level of selectivity on the data?
If Yes, and it is frequently the target of a WHERE clause, then add that index.
Have I dropped the indexes I no longer need?
If not, why not?
Do I have a maintenance strategy established?
If not, why not?


References sites:

http://searchsqlserver.techtarget.com/generic/0,295582,sid87_gci1239952,00.html

http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx

http://tonesdotnetblog.wordpress.com/2008/05/26/twelve-tips-for-optimising-sql-server-2005-queries/

http://blog.sqlauthority.com/2009/02/07/sql-server-introduction-to-force-index-query-hints-index-hint/ -- Forced indexes.

http://blog.decaresystems.ie/index.php/2007/07/11/index-usage-in-sql-server-2005/ -- Index usage

http://databases.about.com/od/sqlserver/a/indextuning.htm

http://www.sql-server-performance.com/tips/rebuilding_indexes_p1.aspx

http://www.sqlteam.com/article/sql-server-indexes-the-basics



Disabling Indexes:

http://msdn.microsoft.com/en-us/library/ms177406.aspx

SQL SERVER 2005: Points to Ponder

SQL SERVER 2005: Points to Ponder

Built in system databases:
master
Purpose: This db holds a special set of tables (system tables) that keeps track of the system as a whole.
Example:
When you create a new db on the server, an entry is placed in the sysdatabases table in the master db. Note: This db is critical to your system and cannot be deleted.
model
Purpose: As its name implies, it forms a Template for any new db that you create.
Example:
You could add a set of audit tables that you include in every db you build.
You could also create a user groups that would be cloned into every db that was created on the system.
Note: Since this db servers as the template for any other db’s, its required db and must be left on the system; you cannot delete it.
msdb
Purpose: A process named SQL Agent Process stores any system tasks in this db.
Example:
Schedule a stored procedure for one time execution, and yes, it has an entry in msdb. Note: you cannot delete it.
tempdb
Purpose:
Whenever you issue a complex or large query that SQL Server needs to build interim tables to solve, it does so in tempdb.
Whenever you create a temporary table of your own, it is created in tempdb.
Whenever there is a need for data to be stored in temporarily, it’s probably stored in tempdb.
tempdb is very different from any other db. Not only are the objects within it temporary; the database itself is temporary. It has the distinction of being the only db in your system that is completely rebuilt from scratch every time you start your SQL Server.
Note: Creating objects directly in tempdb is different than creating from your own db.
There is no way to add a column to specific location in SQL Server. If you want to move a column to the middle, you need to create a completely new table (with different name), copy the data over to the new table, DROP the existing table, and then rename the new one.
This issue of moving columns around get very sticky indeed. Even some of the tools that supposed to automate this often have problems with it. Why? Well, any foreign key constraints you have that reference this table must first be dropped before you are allowed to delete the current version of the table. That means that you have to drop all your foreign keys, make the changes, and then add all your foreign keys back. It doesn’t end there, however, any indexes you have defined on the old table are automatically dropped when you drop the existing table – that means that you must remember to re-create your indexes as part of the build script to create your new version of the table – yuck!
But wait! There’s more! While we haven’t really looked at views yet, I feel compelled to make a reference here to what happens to your views when you add a column. You should be aware that, even if your view is built using a SELECT * as its base statement, your new column will not appear in your view until you rebuild the view. Column names in views are resolved at the time the view is created for performance reasons. That means any views that have already been created when you add your columns have already resolved using the previous columns list – you must either DROP and re-create the view or use an ALTER VIEW statement to rebuild it.

If you want to add a NOT NULL column after the fact, you have the issue of
what to do with rows that already have NULL values. We have shown the solution to that here by providing a default value. The default is then used to populate the new column for any row that is already in our table.
Before CREATE TABLE Employee(

LastRaiseDate datetime NULL,

)
GO
INSERT INTO Employee…
After
ALTER TABLE Employee
ALTER COLUMN LastRaiseDate datetime NOT NULL DEFAULT ‘2005-01-01’
GO
Comparison operators – these work as they do in pretty much any programming language with couple of notable points:
What constitutes "greater than," "less than,"
and "equal to" can change depending on the collation order you have selected. For example, "ROMEY" = "romey" in places where case-insensitive sort order has been selected, but "ROMEY" <> "romey" in a case-sensitive situation.
!= and <> both mean, "not equal". "!<" and "!>" means "not less than" and "not greater than" respectively.
char and varchar: When n(i.e., size) is not specified in a data definition or variable declaration statement, the default length is 1. When n is not specified when using the CAST and CONVERT functions, the default length is 30.

Logical Operators – You can use these to combine multiple conditions into one WHERE clause. NOT is evaluated first, then AND, then OR. If you need to change the evaluation order, you can use parentheses. Note that XOR is not supported.
Note that, once we use a GROUP BY, every column in the SELECT list has to either be part of the GROUP BY or it must be an aggregate.

Actually, all aggregate functions ignore NULLs except for COUNT (*). Think about this for a minute – it can have a very significant impact on your results. Many users expect NULL values in numeric fields to be treated as zero when performing averages, but a NULL does not equal zero, and as such, shouldn’t be used as one. If you perform an AVG or other aggregating unless you manipulating them into a non-NULL value inside the function (using COALESE () or ISNULL for example). But beware of this when coding in T-SQL and when designing your database.

Why does it matter in your database design? Well, it can have a bearing on whether you decide to allow NULL values in a field or not by thinking about the way that queries are likely to be run against the database and how you want your aggregates to work.
Note that you can use DISTINCT with any aggregate function, although I question whether many of the functions have any practical use for it. For example, I can’t imagine why you would want an average of just the DISTINCT rows.

ALL is perhaps best understood as being the opposite of DISTINCT. Where DISTINCT is used to filter out duplicate rows, ALL says to include every row. ALL is the default FOR any SELECT statement except for situations where there is a UNION. We can discuss the differences between ALL and UNION in further points.

On the issue of, "Should I specifically state a value for all columns or not?" I really recommend naming every column every time – even if you just use the DEFAULT keyword or explicitly state NULL. DEFAULT will tell SQL Server to use whatever the default value is for that column (if there isn’t one, you’ll get an error).

What’s nice about this is the readability of code – this way it’s really clear what you are doing. In addition, I find that explicitly addressing every column leads to fewer bugs.
A normalized database is one where the data has been broken out from larger tables into many smaller tables for the purpose of eliminating repeating data, saving space, improving performance, and increasing data integrity. It’s great stuff and vital to relational database; however it also means that you wind up getting your data from here, there, and everywhere.

Note: In joining two or more tables, one good principle to adopt on is this to select what you need, and need what you select. What I’m getting at here is that every additional record or column that you return takes up additional network bandwidth, and often, additional query processing on your SQL Server. The upshot is that selecting unnecessary information hurts performance not only for the current user, but also for every other user of the system and for user of the network on which the SQL Server resides.

Select only the columns that you are going to be using and make your WHERE clause as restrictive as possible.

Keep in mind that, however that an IDENTITY and a PRIMARY KEY are completely separate notions – that is, just because you have an IDENTITY column doesn’t mean that the value is unique(for example, you can reset the seed value and count back up through values you’ve used before). IDENTITY values are usually used as the PRIMARY KEY column, but they don’t have to be used that way.

It’s worth nothing that an identity column works sequentially. That is, once you’ve set a seed (the starting point) and the increment, your values only go up (or down if you set the increment to a negative number). There is no automatic mechanism to go back and fill in the numbers for any rows you may have deleted. If you want to fill in blank spaces like that, you need to use SET IDENTITY_INSERT {ON|OFF}, which allows you to turn off (yes, turning it "on" turns it off – that is, you are turning on the ability to insert your own values, which has the effect of turning off the automatic value) the identity process for inserts from the current connection. This can, however, create havoc if you’re not careful or if people are still trying to use the system as you do this, so tread carefully.

I highly recommend explicitly stating the NULL option for every column in every table you ever build. Why? As I mentioned before, there are a large number of different settings that can affect what the system uses a default for the nullability of a column. If you rely on these defaults, then you may find later that your scripts don’t seem to work right (because you or someone else has changed a relevant setting without realizing its full effect).

Note on "Computed Columns":
You cannot use a sub query, and the values cannot come from a different table.
Prior to SQL Server 2000, you could not use a computed column as any part of any key (primary, foreign, or unique) or with a default constraint. For SQL Server 2005, you can now use a computed column in constraints (you must flag the computed column as persisted if you do this however).

Another problem for previous versions (but added back in SQL Server 2000) is the ability to create indexes on computed columns. You can create indexes on computed columns, but there are special steps you must take to do so.
Technically speaking, you can execute a sproc by simply calling it(without using the EXEC keyword). The problem is that this only works consistently if the sproc being called is the first statement of any kind in the batch. Just having , for example, sp_help would have worked in the place of the code, but if you tried to run a SELECT statement before it – it would blow up on you. Not using EXEC leads to very unpredictable behavior and should be avoided.
For the code that you write directly in T-SQL, SQL Server will automatically adjust to the padded spaces issue – that is, an ‘xx’ placed in a char(5) will be treated as being equal (if compared) to an ‘xx’ placed in a varchar (5) – this is not, however, true in your client APIs such as ADO and ADO.NET. If you connect to a char (5) in ADO, then an ‘xx’ will evaluate to ‘xx ‘ with three spaces after it – If you compare it to ‘xx’, it will evaluate to False. An ‘xx’ placed in a varchar (5), however, will automatically have any trailing spaces trimmed, and comparing it to ‘xx’ in ADO will evaluate to true.
Note: If SET ANSI_PADDING is OFF when either CREATE TABLE or ALTER TABLE is executed, a char column that is defined as NULL is handled as varchar.
Note that the actual column being referenced must have either a PRIMARY KEY or a UNIQUE constraint defined on it.
Unlike primary keys, we are not limited to just one foreign key on a table. We can have between 0 and 253 foreign keys in each table. The only limitation is that a given column can reference only one foreign key. However, you can have more than one column participate in a single foreign key. A given column that is the target of a reference by a foreign key can also be referenced by many tables.
By default, you cannot delete a record or update the referenced column in a referenced table if that record is referenced from the dependent table. If you want to be able to delete or update such a record, then you need to set up a CASCADE action for the delete and/or update.

There is something of a gotcha when creating foreign keys that reference the same table the foreign key is being defined on. Foreign keys of this nature are not allowed to have declarative CASCADE actions. The reason for this restriction is to avoid cyclical updates or deletes – that is, situations where the first update causes another, which in turn tries to update the first. The result could be a never-ending loop.
Don’t confuse the space that an extent is taking up with the space that a database takes up. Whatever space is allocated to the database is what you’ll see disappear from your disk drive’s available space number. An extent is merely how things are, in turn, allocated within the total space reserved by the database.
Unlike a primary key, a UNIQUE constraint does not automatically prevent you from having a NULL value. Whether NULLs are allowed or not depends on how you set the NULL option for that column in the table. Keep in mind, however, that, if you do allow NULLs, you will be to insert only one of them(although a NULL doesn’t equal to another NULL, they are still considered to be duplicate from the perspective of a UNIQUE constraint)

A table can have maximum of 1024 columns.
In SQL Server, we have a number of different collation options available to us. Among these options are:
Binary: Sorts by the numeric representation of the character(for example, in ASCII, a space is represented by the number 32, the letter "D" is 68, but the letter "d" is 100). Because everything is numeric, this is the fastest option – unfortunately, it’s also not all the way in which people think, and can also really wreak havoc with comparisons in your WHERE clause.
Dictionary order: This sorts things just as you would expect to see in a dictionary, with a twist you can set a number of different additional options to determine sensitivity to case, accent, and character set.
The point here is that what happens in your indexes depends on the collation information you have established for your data. Collation can be set at the database and column level, so you have a fairly fine granularity in your level of control.
Once the collation order has been set, changing it is very non-trivial (but possible), so be certain of the collation order you want before you set it.
See if you can spot why the use of EXISTS in the WHERE clause of your queries has so much to offer performance-wise where it fits the problem. When you use the EXISTS operator, SQL Server stops as soon as it finds one record that matches the criteria. If you had a million record table, and it found a matching record on the third record, then use of EXISTS option would have saved you the reading of 999,997 records! "NOT EXISTS" works in much the same way.

Derived Tables: A derived table is made up of the columns and rows of a result set from a query. Keep in mind that derived tables aren’t the solutions for everything. For example, if the result set is going to be fairly large and you’re going to have lots of joined records, then you may want to look at using temporary table and building an index on it (derived tables have no indexes). Every situation is different, but now you have one more tool in your arsenal.
Needless to say, page splits can have a very negative impact on system performance, and are characterized by behavior where your process on the server seems to just for a new second (while the pages are being split and re-written).
The main things to understand about a DEFAULT constraint are that:
Defaults are only used in INSERT statements – they are ignored for UPDATE and DELETE statements.
If any value is supplied in the INSERT, then the default is not used.
If no value is supplied, the default will always be used.
You can mix and match any and all constraints as you choose – just be careful not to create constraints that have mutually exclusive conditions. For example, don’t have one constraint that says that col1 > col2 and another one that says that col2 > col1. SQL Server will let you do this, and you wouldn’t see the issues with it until run time.
You cannot disable PRIMARY KEY or UNIQUE constraints.
Temporally disabling an existing constraint: We can run an ALTER statement with an option called NOCHECK that turns off the constraint in question:
Eg: ALTER TABLE Customers NOCHECK CONSTRAINT CN_CustomerPhoneNo To enable the above constraint again, use CHECK option rather than NOCHECK:
Eg: ALTER TABLE Customers CHECK CONSTRAINT CN_CustomerPhoneNo
Choosing what to Use:

Restriction Pros Cons
Constraints Fast.
Can reference other columns. Happens before the command occurs.
ANSI-complaint.
Must be refined for each table.
Can’t reference other tables.
Can’t be bound to data types.
Rules, Defaults Independent objects.
Reusable.
Can be bound to data types.
Happens before the command occurs.
Slightly slower.
Can’t reference across columns.
Can’t reference other tables.
Really meant for backward compatibility only!!!
Triggers Ultimate flexibility.
Can reference other columns and other tables. Can even use .NET to reference information that is external to your SQL Server.
Happens after the command occurs.
High overhead.

Auditing: Displaying Existing Code:
sp_helptext
The syscomments system table
Using sp_helptext is highly preferable, as when new release come out, it will automatically be updated for changes to the system tables.
Not that the restriction on using the ORDER BY clause applies only to the code within the view. Once the view is created, you can still use an ORDER BY clause when you reference the view in a query.
Batches: A batch is a grouping of T-SQL statements into one logical unit. All of the statements within a batch are combined into one execution plan, so all statements are parsed together and must pass a validation of the syntax or none of the statements will execute. Note, however, that this does not prevent runtime errors, from happening. In the event of a runtime error, any statement that has been executed prior to the runtime error will still be in effect. To summarize, if a statement fails at parse-time, then nothing runs. If a statement fails at runtime, then all statements until the statement that generated the error have already run.

For ex:

DECLARE @MyVariable varchar(50)

SELECT @MyVariable = 'hi this is a sample test on batches'

PRINT 'Done with the first Batch....'

GO

PRINT @MyVariable -- This generates an error since @MyVariable isn't declared in this batch

PRINT 'Done with the second Batch'

GO

PRINT 'Done with third Batch' -- Notice that this still gets executed even after the error.

GO

Result:

Done with the first Batch....

Msg 137, Level 15, State 2, Line 2

Must declare the scalar variable "@MyVariable".

Done with third Batch
To separate a script into multiple batches, we make use of the GO statement. The GO statement:
Must be on its own line (nothing other than a comment can be on the same like). For ex: SELECT * FROM Customers WHERE CustomerID = ‘ALFKI’ GO
All statements combined into one execution plan and sent to server independently of any other batches.
Is not a T-SQL command, but, rather, a command recognized by the various SQL Server command utilities(OSQL, ISQL, and the Query Analyzer)
Is tried to execute in a pass-through query using ODBC, OLE DB, ADO, ADO.NET or any other access method, you’ll get an error message back from the server. The GO is merely an indicator to the tool that it is time to end the current batch, and time, if appropriate, to start a new one.
INDEXES:
Clustered indexes are usually faster than non-clustered indexes (one could come very close to saying always, but there are exceptions).
Only place non-clustered indexes on columns where you are going to get a high level of selectivity(that is, 95 percent or more of the rows are unique)
All DML statements (INSERT, DELETE, UPDATE) and SELECT statement can benefit from indexes, but insert, deletes, and updates (remember they use a delete and insert approach) are slowed by indexes. The lookup part of a query is helped by the index, but any thing modifies data will have extra work to do (to maintain the index in addition to the actual data).
Indexes take up space.
Indexes are used only if the first column in the index is relevant to your query.
Indexes can hurt as they help – know why you’re building the index, and don’t build indexes you don’t need.
Indexes can provide structured data performance to your unstructured XML data, but keep in mind that, like other indexes, there is overhead involved.
When you’re thinking about indexes, ask yourself, these questions:

Questions Response
Are there a lot of inserts or modifications to this table? If yes, keep indexes to a minimum. This kind of table usually has modifications done through single record lookups of the primary key – usually, this is the only index you want on the table. If the inserts are non-sequential, think about not having a clustered index.
Is this a reporting table? That is, not many insert, but reports run lots of different ways? More indexes are fine. Target the clustered index to frequently used information that is likely to be extracted in ranges. OLAP installations will often have many times the number of indexes seen in an OLTP environment.
Is there a high level of selectivity on the data? If Yes, and it is frequently the target of a WHERE clause, then add that index.
Have I dropped the indexes I no longer need? If not, why not?
Do I have a maintenance strategy established? If not, why not?

SQLCMD
Keep in mind that the options/flags provided by this command utility are case sensitive.

Sunday, February 19, 2012

Best Practices for Speeding Up Your Web Site

Best practices for making web pages fast. The list includes 22 best practices.

  1. Minimize HTTP Requests
  2. Gzip Components
  3. Put Stylesheets at the Top
  4. Put Scripts at the Bottom
  5. Avoid CSS Expressions
  6. Make JavaScript and CSS External
  7. Reduce DNS Lookups
  8. Minify JavaScript and CSS
  9. Avoid Redirects
  10. Remove Duplicate Scripts
  11. Configure ETags
  12. Make Ajax Cacheable
  13. Flush the Buffer Early
  14. Use GET for AJAX Requests
  15. Minimize the Number of iframes
  16. No 404s
  17. Reduce Cookie Size
  18. Avoid Filters
  19. Optimize Images
  20. Optimize CSS Sprites
  21. Don't Scale Images in HTML
  22. Avoid Empty Image src

Minimize HTTP Requests

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.
One way to reduce the number of components in the page is to simplify the page's design. But is there a way to build pages with richer content while also achieving fast response times? Here are some techniques for reducing the number of HTTP requests, while still supporting rich page designs.

Combined files
are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times.

CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.
Image maps combine multiple images into a single image. The overall size is about the same, but reducing the number of HTTP requests speeds up the page. Image maps only work if the images are contiguous in the page, such as a navigation bar. Defining the coordinates of image maps can be tedious and error prone. Using image maps for navigation is not accessible too, so it's not recommended.
Inline images use the data: URL scheme to embed the image data in the actual page. This can increase the size of your HTML document. Combining inline images into your (cached) stylesheets is a way to reduce HTTP requests and avoid increasing the size of your pages. Inline images are not yet supported across all major browsers.
Reducing the number of HTTP requests in your page is the place to start. This is the most important guideline for improving performance for first time visitors. As described in Tenni Theurer's blog post Browser Cache Usage - Exposed!, 40-60% of daily visitors to your site come in with an empty cache. Making your page fast for these first time visitors is key to a better user experience.

Gzip Components

The time it takes to transfer an HTTP request and response across the network can be significantly reduced by decisions made by front-end engineers. It's true that the end-user's bandwidth speed, Internet service provider, proximity to peering exchange points, etc. are beyond the control of the development team. But there are other variables that affect response times. Compression reduces response times by reducing the size of the HTTP response.
Starting with HTTP/1.1, web clients indicate support for compression with the Accept-Encoding header in the HTTP request.
      Accept-Encoding: gzip, deflate
If the web server sees this header in the request, it may compress the response using one of the methods listed by the client. The web server notifies the web client of this via the Content-Encoding header in the response.
      Content-Encoding: gzip
Gzip is the most popular and effective compression method at this time. It was developed by the GNU project and standardized by RFC 1952. The only other compression format you're likely to see is deflate, but it's less effective and less popular.
Gzipping generally reduces the response size by about 70%. Approximately 90% of today's Internet traffic travels through browsers that claim to support gzip. If you use Apache, the module configuring gzip depends on your version: Apache 1.3 uses mod_gzip while Apache 2.x uses mod_deflate.
Gzipping as many file types as possible is an easy way to reduce page weight and accelerate the user experience.

Put Stylesheets at the Top

Moving stylesheets to the document HEAD makes pages appear to be loading faster. This is because putting stylesheets in the HEAD allows the page to render progressively.

Front-end engineers that care about performance want a page to load progressively; that is, we want the browser to display whatever content it has as soon as possible. This is especially important for pages with a lot of content and for users on slower Internet connections. The importance of giving users visual feedback, such as progress indicators, has been well researched and documented. In our case the HTML page is the progress indicator! When the browser loads the page progressively the header, the navigation bar, the logo at the top, etc. all serve as visual feedback for the user who is waiting for the page. This improves the overall user experience.

The problem with putting stylesheets near the bottom of the document is that it prohibits progressive rendering in many browsers, including Internet Explorer. These browsers block rendering to avoid having to redraw elements of the page if their styles change. The user is stuck viewing a blank white page.
The HTML specification clearly states that stylesheets are to be included in the HEAD of the page: "Unlike A, [LINK] may only appear in the HEAD section of a document, although it may appear any number of times." Neither of the alternatives, the blank white screen or flash of unstyled content, are worth the risk. The optimal solution is to follow the HTML specification and load your stylesheets in the document HEAD.

Put Scripts at the Bottom


The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.

In some situations it's not easy to move scripts to the bottom. If, for example, the script uses document.write to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to workaround these situations.

An alternative suggestion that often comes up is to use deferred scripts. The DEFER attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. Unfortunately, Firefox doesn't support the DEFER attribute. In Internet Explorer, the script may be deferred, but not as much as desired. If a script can be deferred, it can also be moved to the bottom of the page. That will make your web pages load faster.

Avoid CSS Expressions

CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically. They were supported in Internet Explorer starting with version 5, but were deprecated starting with IE8. As an example, the background color could be set to alternate every hour using CSS expressions:
background-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );
As shown here, the expression method accepts a JavaScript expression. The CSS property is set to the result of evaluating the JavaScript expression. The expression method is ignored by other browsers, so it is useful for setting properties in Internet Explorer needed to create a consistent experience across browsers.

Make JavaScript and CSS External

Many of these performance rules deal with how external components are managed. However, before these considerations arise you should ask a more basic question: Should JavaScript and CSS be contained in external files, or inlined in the page itself?
Using external files in the real world generally produces faster pages because the JavaScript and CSS files are cached by the browser. JavaScript and CSS that are inlined in HTML documents get downloaded every time the HTML document is requested. This reduces the number of HTTP requests that are needed, but increases the size of the HTML document. On the other hand, if the JavaScript and CSS are in external files cached by the browser, the size of the HTML document is reduced without increasing the number of HTTP requests.
The key factor, then, is the frequency with which external JavaScript and CSS components are cached relative to the number of HTML documents requested. This factor, although difficult to quantify, can be gauged using various metrics. If users on your site have multiple page views per session and many of your pages re-use the same scripts and stylesheets, there is a greater potential benefit from cached external files.

Reduce DNS Lookups

The Domain Name System (DNS) maps hostnames to IP addresses, just as phonebooks map people's names to their phone numbers. When you type www.yahoo.com into your browser, a DNS resolver contacted by the browser returns that server's IP address. DNS has a cost. It typically takes 20-120 milliseconds for DNS to lookup the IP address for a given hostname. The browser can't download anything from this hostname until the DNS lookup is completed.

Minify JavaScript and CSS

Minification is the practice of removing unnecessary characters from code to reduce its size thereby improving load times. When code is minified all comments are removed, as well as unneeded white space characters (space, newline, and tab). In the case of JavaScript, this improves response time performance because the size of the downloaded file is reduced. Two popular tools for minifying JavaScript code are JSMin and YUI Compressor. The YUI compressor can also minify CSS.
Obfuscation is an alternative optimization that can be applied to source code. It's more complex than minification and thus more likely to generate bugs as a result of the obfuscation step itself. In a survey of ten top U.S. web sites, minification achieved a 21% size reduction versus 25% for obfuscation. Although obfuscation has a higher size reduction, minifying JavaScript is less risky.
In addition to minifying external scripts and styles, inlined
An alternative in PHP would be to create a function called insertScript.




In addition to preventing the same script from being inserted multiple times, this function could handle other issues with scripts, such as dependency checking and adding version numbers to script filenames to support far future Expires headers.

Configure ETags

Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser's cache matches the one on the origin server. (An "entity" is another word a "component": images, scripts, stylesheets, etc.) ETags were added to provide a mechanism for validating entities that is more flexible than the last-modified date. An ETag is a string that uniquely identifies a specific version of a component. The only format constraints are that the string be quoted. The origin server specifies the component's ETag using the ETag response header.
HTTP/1.1 200 OK
Last-Modified: Tue, 12 Dec 2006 03:03:59 GMT
ETag: "10c24bc-4ab-457e1c1f"
Content-Length: 12195

Make Ajax Cacheable

Flush the Buffer Early

When users request a page, it can take anywhere from 200 to 500ms for the backend server to stitch together the HTML page. During this time, the browser is idle as it waits for the data to arrive. In PHP you have the function flush(). It allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. The benefit is mainly seen on busy backends or light frontends.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
      ... 
    
    
    
      ... 

Use GET for AJAX Requests

when using XMLHttpRequest, POST is implemented in the browsers as a two-step process: sending the headers first, then sending data. So it's best to use GET, which only takes one TCP packet to send (unless you have a lot of cookies). The maximum URL length in IE is 2K, so if you send more than 2K data you might not be able to use GET.

An interesting side affect is that POST without actually posting any data behaves like GET. Based on the HTTP specs, GET is meant for retrieving information, so it makes sense (semantically) to use GET when you're only requesting data, as opposed to sending data to be stored server-side.

Minimize the Number of iframes

Iframes allow an HTML document to be inserted in the parent document. It's important to understand how iframes work so they can be used effectively.

www.codeintellects.com

ASP.NET Interview Questions


ASP.NET Interview Questions
This is a list of questions I have gathered and created over a period of time from my experience, many of which I felt where incomplete or simply wrong.  I have finally taken the time to go through each question and correct them to the best of my ability.  However, please feel free to post feedback to challenge, improve, or suggest new questions.  I want to thank those of you that have contributed quality questions and corrections thus far.
There are some questions in this list that I do not consider to be good questions for an interview.  However, they do exist on other lists available on the Internet so I felt compelled to keep them here for easy access.
1.Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.
inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.

2.What’s the difference between Response.Write() andResponse.Output.Write()?
Response.Output.Write() allows you to write formatted output.

3.What methods are fired during the page load?
Init() - when the page is instantiated

Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is displayed to the user as HTML
Unload() - when page finishes loading.

4.When during the page processing cycle is ViewState available?
After the Init() and before the Page_Load(), or OnLoad() for a control.

5.What namespace does the Web page belong in the .NET Framework class hierarchy?

System.Web.UI.Page

6.Where do you store the information about the user’s locale?
System.Web.UI.Page.Culture

7.What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
CodeBehind is relevant to Visual Studio.NET only.

8.What’s a bubbled event?
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

9.Suppose you want a certain ASP.NET function executed on MouseOver for a certain button.  Where do you add an event handler?
Add an OnMouseOver attribute to the button.  Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");

10.What data types do the RangeValidator control support?
Integer, String, and Date.

11.Explain the differences between Server-side and Client-side code?
Server-side code executes on the server.  Client-side code executes in the client's browser.

12.What type of code (server or client) is found in a Code-Behind class?
The answer is server-side code since code-behind is executed on the server.  However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the clients browser.  But just to be clear, code-behind executes on the server, thus making it server-side code.

13.Should user input data validation occur server-side or client-side?  Why?
All user input data validation should occur on the server at a minimum.  Additionally, client-side validation can be performed where deemed appropriate and feasable to provide a richer, more responsive experience for the user.

14.What is the difference between Server.Transfer and Response.Redirect?  Why would I choose one over the other?
Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser.  This provides a faster response with a little less overhead on the server.  Server.Transfer does not update the clients url history list or current url.  Response.Redirect is used to redirect the user's browser to another page or site.  This performas a trip back to the client where the client's browser is redirected to the new page.  The user's browser history list is updated to reflect the new address.

15.Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
Valid answers are:
·  A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.
·  A DataSet is designed to work without any continuing connection to the original data source.
·  Data in a DataSet is bulk-loaded, rather than being loaded on demand.
·  There's no concept of cursor types in a DataSet.
·  DataSets have no current record pointer You can use For Each loops to move through the data.
·  You can store many edits in a DataSet, and write them to the original data source in a single operation.
·  Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.

16.What is the Global.asax used for?
The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

17.What are the Application_Start and Session_Start subroutines used for?
This is where you can set the specific variables for the Application and Session objects.

18.Can you explain what inheritance is and an example of when you might use it?
When you want to inherit (use the functionality of) another class.  Example: With a base class named Employee, a Manager class could be derived from the Employee base class.

19.Whats an assembly?
Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN

20.Describe the difference between inline and code behind.
Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

21.Explain what a diffgram is, and a good use for one?
The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML.  A good use is reading database data to an XML file to be sent to a Web Service.

22.Whats MSIL, and why should my developers need an appreciation of it if at all?
MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.  MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

23.Which method do you invoke on the DataAdapter control to load your generated dataset with data?
The Fill() method.

24.Can you edit data in the Repeater control?
No, it just reads the information from its data source.

25.Which template must you provide, in order to display data in a Repeater control?
ItemTemplate.

26.How can you provide an alternating color scheme in a Repeater control?
Use the AlternatingItemTemplate.

27.What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?
You must set the DataSource property and call the DataBind method.

28.What base class do all Web Forms inherit from?
The Page class.

29.Name two properties common in every validation control?
ControlToValidate property and Text property.

30.Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
DataTextField property.

31.Which control would you use if you needed to make sure the values in two different controls matched?
CompareValidator control.

32.How many classes can a single .NET DLL contain?
It can contain many classes.

Web Service Questions
1.What is the transport protocol you use to call a Web service?
SOAP (Simple Object Access Protocol) is the preferred protocol.

2.True or False: A Web service can only be written in .NET?
False

3.What does WSDL stand for?
Web Services Description Language.

4.Where on the Internet would you look for Web services?

5.True or False: To test a Web service you must create a Windows application or Web application to consume this service?
False, the web service comes with a test page and it provides HTTP-GET method to test.

State Management Questions
1.What is ViewState?
ViewState allows the state of objects (serializable) to be stored in a hidden field on the page.  ViewState is transported to the client and back to the server, and is not stored on the server or any other external source.  ViewState is used the retain the state of server-side objects between postabacks.

2.What is the lifespan for items stored in ViewState?
Item stored in ViewState exist for the life of the current page.  This includes postbacks (to the same page).

3.What does the "EnableViewState" property do?  Why would I want it on or off?
It allows the page to save the users input on a form across postbacks.  It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser.  When the page is posted back to the server the server control is recreated with the state stored in viewstate.

4.What are the different types of Session state management options available with ASP.NET?
ASP.NET provides In-Process and Out-of-Process state management.  In-Process stores the session in memory on the web server.  This requires the a "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server.  Out-of-Process Session state management stores data in an external data source.  The external data source may be either a SQL Server or a State Server service.  Out-of-Process state management requires that all objects stored in session are serializable.

www.codeintellects.com

JavaScript Object-Oriented Programming


It may be shocking news, but JavaScript is a very powerful object-based (or prototype-based, whatever you wish to call it) language. Yes, JavaScript is a powerful language, not just something that's handy for image rollovers and other corny, flashy effects. However, very few people who have used JavaScript realize its capabilities. If you're one of these people, this tutorial is aimed at you. 

First of all, JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java, but it is an object-based language. So, why should you use objects? Not only do they help you better understand how JavaScript works, but in large scripts, you can create self-contained JavaScript objects, rather than the procedural code you may be using now. This also allows you to reuse code more often.
I hope that this article will turn an intermediate JavaScripter who's itching to learn objects, into an expert, keen on the exciting object-oriented JavaScript world!
In this tutorial, you'll learn:
  • JavaScript's primitive data types
  • What an object is in JavaScript
  • How to create custom objects
  • What a constructor is
  • What an object's prototype property is

JavaScript's Primitive Data Types
JavaScript has five primitive data types:
  • Undefined,
  • Null,
  • Boolean,
  • Number, and
  • String. Throughout this tutorial, we'll use the latter three extensively.
  • A Boolean is a logical entity that consists of either a true or a false value. An example of one is:
    var BooleanValue = true;
    A Number is a set of numerical digits that represent a number. Through this tutorial, we'll only use base-10 numbers. An example:
    var NumericalValue = 354;
    A String is a set of zero or more characters. An example:
    var StringValue = "This is a String";


    Typeof
    A less-known operator in JavaScript is the typeof operator. It tells you what type of data you're dealing with. Makes sense, huh? Let's look at some examples:
    var BooleanValue = true;
    var NumericalValue = 354;
    var StringValue = "This is a String";
    alert(typeof BooleanValue) // displays "boolean"
    alert(typeof NumericalValue) // displays "number"
    alert(typeof StringValue) // displays "string"


    An Object
    An object is a collection of properties. These properties can either be primitive data types, other objects, or functions (which in this case are called methods, but more on this later). A constructor function (or simply, constructor) is a function used to create an object - this too we'll discuss in detail later. JavaScript comes with many built-in objects, such as the Array, Image, and Date objects. Many of you are familiar with Image objects from creating those ever-so-cute rollover effects. Well, when you use the code
    var Image1 = new Image();
    Image1.src = "myDog.gif";

    you have in fact created a new Image object, and assigned a property of your new Image object: the src property. Image1 is a new Image object; in other words, it is an instance of the Image object. Using JavaScript's dot-structure ( . ), the code above then accesses and sets the src property of your new Image object. Now, let's learn how to create our own objects.

    function myFunc(){
    }

    var myObject = new myFunc();
    alert(typeof myObject);  // displays "object"

    We've just created our own object. In fact we've created a myFunc object. myFunc() is a constructor function; it lays out the blueprint from which objects that are created from it will follow (although, in this case, it doesn't lay out much of a blueprint). So, how does JavaScript know to create an instance of the myFunc object, rather than to return its results? Let's compare the example above with the following, more conventional use of a function:
    function myFunc(){
     return 5;
    }

    var myObject = myFunc();
    alert(typeof myObject); // displays "number"

    In this case, we've assigned 5 to myObject. So, what's the difference between these two scripts? Answer: the new keyword. It tells JavaScript to create an object following the blueprint set forth in the myFunc() constructor function. In fact, when we create an Image object, we do the same thing, except that instead of using our own constructor function, we use one of JavaScript's built-in constructor functions, the Image() constructor function.
    So far, we've learned how to create a constructor function, and how to create an object from that constructor function. In our example, we've created a myFunc() constructor and created an instance of the myFunc object, which we assigned to the variable myObject.
    This is all fine and dandy, but what's the point? Well, just like our Image object, myObject can be assigned properties:
    function myFunc(){
    }

    var myObject = new myFunc();
    myObject.StringValue = "This is a String";
    alert(myObject.StringValue); // displays "This is a String"

    And voila, we've now created a property for our object. However, if we create another instance of the myFunc object (using the myFunc() constructor function), we also have to assign the StringValue property to this new instance. For example:
    function myFunc(){
    }

    var myObject = new myFunc();
    myObject.StringValue = "This is a String";
    var myObject2 = new myFunc();
    alert(myObject2.StringValue); // displays "undefined"

    So, how can we create properties that exist for all myFunc objects? Within the myFunc() constructor function, we can do just that. The this keyword inside a constructor function refers to the object that's being created. Example:
    function myFunc(){
     this.StringValue = "This is a String";
    }

    var myObject = new myFunc();
    var myObject2 = new myFunc();
    alert(myObject2.StringValue); // displays "This is a String"

    Now, all myFunc objects will have a StringValue property, assigned with the initial value of "This is a String", but every object can have its own distinctive value for StringValue. In other words, we can change the StringValue property for one myFunc object, without affecting the others:
    function myFunc(){
     this.StringValue = "This is a String";
    }

    var myObject = new myFunc();
    myObject.StringValue = "This is myObject's string";
    var myObject2 = new myFunc();
    alert(myObject.StringValue); // displays "This is myObject's string"
    alert(myObject2.StringValue); // displays "This is a String"

    We can also achieve similar results if we pass arguments to our constructor function:
    function myFunc(StringValue){
     this.StringValue = StringValue;
    }

    var myObject = new myFunc("This is myObject's string");
    var myObject2 = new myFunc("This is a String");
    alert(myObject.StringValue); // displays "This is myObject's string"
    alert(myObject2.StringValue); // displays "This is a String"

    In the myFunc() constructor, this.StringValue refers to the property being assigned to the newly created object, while StringValue refers to the function's local variable that was passed as an argument. So, now that we've assigned properties to objects, what about methods?


    Object Methods
    In addition to properties, objects can have methods. An object's method is a function it can perform. Let's take a look at this example. For this one, let's create a Circle object. First, we're going to have to define our functions, and then make them methods of our Circle object. Let's define our Circle() constructor and a Circle object or two:
    function Circle(radius){
     this.radius = radius;
    }

    var bigCircle = new Circle(100);
    var smallCircle = new Circle(2);

    Now, let's define some functions that we might use:
    function getArea(){
     return (this.radius*this.radius*3.14);
    }

    function getCircumference(){
     var diameter = this.radius*2;
     var circumference = diameter*3.14;
     return circumference;
    }

    Note that if you were going for accuracy, you could use Math.PI instead of 3.14, but we'll use this simplified representation of pi to keep the numbers in our examples nice and round.
    These functions are easy, except for one thing: what does this.radius refer to? this always refers to the current object, in this case, the Circle object. So this.radius refers to the radius property of the Circle object. So, how do we attach these functions to our object? It's not as hard as you might think. Let's change our Circle() constructor:
    function Circle(radius){
     this.radius = radius;
     this.getArea = getArea;
     this.getCircumference = getCircumference;
    }

    The above assigns the functions getArea and getCircumference to our Circle object, making them methods—functions belonging to our Circle object. We can use methods just like any normal function, but we must first access the object in which the method is encapsulated:
    alert(bigCircle.getArea()); // displays 31400
    alert(bigCircle.getCircumference()); // displays 618
    alert(smallCircle.getArea()); // displays 12.56
    alert(smallCircle.getCircumference()); // displays 12.56

    Let's say we want to keep all our properties and methods in the same place - in the Circle() constructor function. There are many ways to do this. Let's first examine inner functions. An inner function is a function within a function (say that sentence quickly ten times!). Here's what they let us do:
    function Circle(radius){  
     function getArea(){  
       return (this.radius*this.radius*3.14);  
     }  
     function getCircumference(){  
       var diameter = this.radius*2;  
       var circumference = diameter*3.14;  
       return circumference;  
     }  
    this.radius = radius;  
    this.getArea = getArea;  
    this.getCircumference = getCircumference;  
    }

    It's the same code, except that we've moved the functions. Now, inside our two functions, instead of this.radius, we could use just plain old radius because inner functions can access local variables within outer functions. Thus, it would be able to access the radius local variable passed as an argument to the Circle() constructor. Therefore, we could have just as easily used:
    function Circle(radius){  
     function getArea(){  
       return (radius*radius*3.14);  
     }  
     function getCircumference(){  
       var diameter = radius*2;  
       var circumference = diameter*3.14;  
       return circumference;  
     }  
     this.radius = radius;  
     this.getArea = getArea;  
     this.getCircumference = getCircumference;  
    }

    Ok, now let's change the radius of an object and get its area:
    bigCircle.radius=50;  
    alert(bigCircle.getArea()); // displays 31400

    But wait! It returns 31400, rather than the expected 7850. What's wrong? Well, radius refers to the value we passed to the Circle() constructor function, not the value of the object. So when we change the object's radius, the methods getArea() and geCircumference(), keep on using the old radius. So, we really shouldn't use just plain old radius. Instead, we need to use this.radius, as it refers to the current object's radius, whether this property changes after the object is created or not.

    Ok, so now we've created a self-contained object constructor - the function that defines an object. Let's look at another way we can create functions inside our Circle() constructor:
    function Circle(radius){  
     this.radius = radius;  
     this.getArea = function(){  
       return (this.radius*this.radius*3.14);  
     }  
     this.getCircumference = function(){  
       var diameter = this.radius*2;  
       var circumference = diameter*3.14;  
       return circumference;  
     }  
    }  
     
    var bigCircle = new Circle(100);  
    var smallCircle = new Circle(2);  
     
    alert(bigCircle.getArea()); // displays 31400  
    alert(smallCircle.getCircumference()); // displays 12.56

    Here, we've encountered another way to define a function. We can use:
    functionName = function([parameters]){  
     // function body  
    }

    In this way, we can create parameters:
    functionName = function(parameter1,parameter2,parameter3){  
     //function body  
    }

    While functions aren't created this way very often, when we're creating objects, they can be useful shortcuts. These processes also help avoid conflicts with function names. For instance, another object can have a different function with the same name, for example getArea(), without causing a conflict. This is possible because these functions are encapsulated inside an object constructor.


    Object Categories
    There are three object categories in JavaScript: Native Objects, Host Objects, and User-Defined Objects.

    Native objects are those objects supplied by JavaScript. Examples of these are String, Number, Array, Image, Date, Math, etc.
    Host objects are objects that are supplied to JavaScript by the browser environment. Examples of these are window, document, forms, etc. And, user-defined objects are those that are defined by you, the programmer.
    A fundamental concept in JavaScript is that every element that can hold properties and methods is an object, except for the primitive data types. We can use JavaScript's built-in constructor functions (just like the ones we've created) to create objects:
    var Image1 = new Image(50,100);  
    Image1.src = "myDog.gif";

    Here we've created a new Image object using the native Image() constructor function with the following properties:
  • width = 50
  • height = 100
  • src = "myDog.gif"
JavaScript also includes an Object() constructor function that can be used to define a new Object object:
var myObj = new Object();
To that "base Object", we can add properties/methods. Every object in JavaScript derives from JavaScript's native Object object.
Let's review a String primitive data type:
var myString = "This is my string";  
alert(myString); // displays "This is my string"  
alert(typeof myString); // displays "string"
However, we can even make a String an object, by using its constructor function:
var myString = new String("This is my string");  
alert(myString); // displays "This is my string"  
alert(typeof myString); // displays "object"
Now we've created a String object. We can also do the same with Number and Boolean. But why would we want to? Well, once we've done that, we can add distinctive properties and methods to that object. A primitive data type contains the properties and methods laid out in its object constructor, but it cannot, itself, hold any distinctive properties/methods. For example, a String primitive data type contains the length property as well as the many methods defined in the native String() object constructor, such as substring(). However, a String object contains the properties and methods defined in the String() object constructor as well as any unique values assigned to that particular object. Now, let's create a Number object and add a method to it:
var myNumber = new Number(2);  
myNumber.doubleIt = new Function("return this*2");  
alert(myNumber.doubleIt()); // displays 4  
alert(typeof myNumber); // displays "object"
So, we just created a new Number object, and then we defined a method for it, doubleIt(). Note that typeof myNumber is "object". This is because objects are able to contain unique properties and methods. Primitive data types, such as String, Boolean, Number, Undefined, and Null, cannot, and this is what differentiates the two.
Also, in the example above, we've in fact created another object - a Function object. However, the Function object is different. When we create an object, we first enter the new keyword, then follow it with the object constructor function, and this returns a new instance of that particular object. Then, using the returned value (which we usually assign to a variable), we can add properties and methods to that object. However, because a Function object is also a callable block of code, JavaScript makes the distinction and tells us that it's not only an object (which it is, as we can add properties and methods to it), but is also a callable block of code. So, when we enter:
alert(typeof myNumber.doubleIt) // displays "function"
it displays "function", rather than "object" as you might have expected. The Function() constructor function can take more arguments. The last argument passed to the Function() constructor becomes the body of the function, while the others become parameters:
var myFunc = new Function("parameter1","parameter2",  
 "parameter3"," // function body");
Now we can call that function and specify three arguments:
myFunc("argument1","argument2","argument3");

Function Objects
JavaScript's Function object is unususal for a number of reasons. Firstly, it's a callable block of code. And a function is always an object - it always has the ability to hold unique properties and methods. The creation of a function automatically creates a Function object:
function myFuncObj(){}  
myFuncObj.someVariable = "x";  
alert(myFuncObj.someVariable) // displays "x"  
Even without the new keyword, Function() creates an object, capable of containing properties and methods. Note that the Function() constructor is a special case – all other constructors must be called with the new keyword, or they simply return a value, instead of a new object.
Let's look at a String primitive data type vs. a String object:
var pimitiveString1 = "This is a primitive string";  
var pimitiveString2 = String("This is a primitive string");  
var stringObject = new String("This is a String object");  
 
primitiveString1.prop = "This is a property";  
primitiveString2.prop = "This is a property";  
stringObject.prop = "This is a property";  
 
alert(primitiveString1.prop) // displays "undefined"  
alert(primitiveString2.prop) // displays "undefined"  
alert(stringObject.prop) // displays "This is a property"  
 
alert(typeof primitiveString1); // displays "string"  
alert(typeof primitiveString2); // displays "string"  
alert(typeof stringObject) // displays "object"
Here you can see that, without the new keyword, we don't create and assign an object to a variable, but instead, we assign the returned value (which is a primitive data type, String) to a variable. You can also see that primitiveString1 and primitiveString2 are not objects, as we cannot assign them properties. Note that primitiveString1/primitiveString2 and stringObject return different results when used with the typeof operator. This is even true for Date, Image, Option, and other objects. For example:
var x = Date();  
alert(typeof x); // displays "string"
No matter how you create a function (there are numerous ways), you'll automatically create an object:
var myFuncObj = new Function();  
var myFuncObj = Function();  
var myFuncObj = function(){}  
function myFuncObj(){}
Here, we've examined the different ways to create a Function object that's capable of holding a callable block of code, as well as any disctinct properties or methods.

In Summary
Before we move on, let's review some key points:
  • In JavaScript, there are five primitive data types: Undefined, Null, Boolean, Number, and String.
  • In JavaScript, everything is an object, except for the primitive data types.
  • An object is an unordered collection of properties. Properties may represent primitive data types, objects, or Function objects, in which case they are called "methods".
  • There are three main object categories in JavaScript: native objects, host objects, and user-defined objects.
  • There are many built-in, native objects, such as Object, Image, Date, Option, etc. However, we can also create our own user-defined objects, such as the Circle object.
  • An object constructor/object constructor function is a function that's used to define a new object. In this function, we declare the initial properties/methods of the new object, and usually assign them a pre-defined value.
  • To create an instance of an object, we use the keyword "new", followed by an object constructor. We can either use JavaScript's built-in constructors to create a native object, or we can build our own constructors to create a user-defined object.
  • Every object method has a variable - this - which refers to the current instance of that object from which the method is called. Example:
    • myObj.myFunc()
    • yourObj.myFunc()

    In the first example, in myFunc(), the variable this would refer to myObj. However, in the second example, in myFunc(), the variable this would refer to yourObj.