please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 2 Next
 

2. Lexical Structure

Contents:
Case Sensitivity
Whitespace and Line Breaks
Optional Semicolons
Comments
Literals
Identifiers
Reserved Words

The lexical structure of a programming language is the set of elementary rules that specify how you write programs in the language. It is the lowest-level syntax of a language, and specifies such things as what variable names look like, what characters are used for comments, and how one program statement is separated from the next. This short chapter explains the lexical structure of JavaScript: it covers the above topics and others.

2.1 Case Sensitivity

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. The while keyword, for example, must be typed "while", and not "While" or "WHILE". Similarly, online, Online, OnLine, and ONLINE are four distinct variable names.

Note that HTML is not case-sensitive, which, because of its close association with JavaScript, can be confusing. In particular, names of event handlers[1] are often typed in mixed-case in HTML (onClick or OnClick, for example) but must be all lowercase when referenced from JavaScript (onclick).

[1] Event handlers are pieces of JavaScript code used as the value of HTML attributes.

Case Sensitivity in Internet Explorer

In Internet Explorer 3.0, the core JavaScript language is case-sensitive, as it is in Navigator. Unfortunately, all of the objects, and their methods and properties, added to this core language by client-side JavaScript are case-insensitive in IE. The Date and Math objects are a built-in part of core JavaScript, so they are case-sensitive in IE; to compute a sine, you must invoke Math.sin(), exactly as shown here. On the other hand, the Document object is part of client-side JavaScript, so it is not case-sensitive. This means that where you would type document.write() in Navigator, you could use Document.Write(), DOCUMENT.WRITE(), or even DoCuMeNt.WrItE() in Internet Explorer.

All user-defined variables, functions, and objects are case-sensitive in IE; it is just the client-side objects and their predefined methods and properties that are not. This does mean, however that you need to be careful how you name your variables and properties. For example, the Window object has a property named parent. In Navigator, it would be perfectly safe to create a new property of a Window object and name it Parent. This would not be okay in IE, however, and would either cause an error or overwrite the value of the parent property.

The reason that client-side objects are not case-sensitive in IE is that IE allows the same client-side objects to be used by the VBScript scripting language. VBScript, like Visual Basic, is not case-sensitive, so Microsoft felt that their client-side objects must not be either. Because of Microsoft's requirement for VBScript, it is not likely that the client-side objects will become case-sensitive in a future version of IE; this is an incompatibility that we will have to live with.

This incompatibility presents a worst-of-both-worlds situation. Because Navigator is case-sensitive, you must be sure to type all your object, method, and property names in exactly the correct case. But because IE is not case-sensitive, you can't take advantage of Navigator's case sensitivity to create different variables with the same spelling and different capitalizations.


Previous Home Next
Exploring JavaScript Book Index Whitespace and Line Breaks

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/ch02_01.htm, 7KB, , updated: 2019/10/14 15:00, local time: 2024/11/22 00:25,
TOP NEW HELP FIND: 
13.58.38.184:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/techref/language/java/script/definitive/ch02_01.htm"> [Chapter 2] Lexical Structure</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .