JavaScript’s Lexical Structure

A programming language’s lexical structure specifies set of some basic rules about how a code should be written in it. Rules like what variable names looks like, the delimiter characters for comments, and how one program statement is separated from the next. It is the lowest-level syntax of a language.

Character Set

Unicode character set is used in JavaScript codes.Almost every writing system is supported by Unicode.

Case Sensitive

JS is a case-sensitive language.While, while, WHILEare all three different words in JavaScript with different meanings and functionality. It means that language keywords, variables, function names, and other identifiers must always be typed with a consistent capitalization of letters.

Whitespaces and Line Breaks

JavaScript is ignorant to spaces that appear between tokens in codes. Line breaks are also not considered by JS. This lets you freely use any number of spaces and newlines. It can help in indentation and formatting of codes which makes them readable and easy to understand.

Comments

Two types of comments are supported by JS.

1)      Single Line. E.g., // this is a single line comment in JS

2)      Multiple Line. E.g.,

/* this is a

multiple line

comment           */

Identifiers and Reserved Words

An identifier is simply a name. A JavaScript identifier must begin with a letter, an underscore (_), or a dollar sign ($). Digits are not allowed as the first character.

Here are some legal identifiers: e, my_name, z3, _flag, $yes.

The identifiers reserved by the language for its use are known as “reserved words”. Below is the table of all the reserved words.

abstractargumentsbooleanbreakbyte
casecatchcharclassconst
continuedebuggerdefaultdeletedo
doubleelseenumevalexport
extendsfalsefinalfinallyfloat
forfunctiongotoifimplements
importininstanceofintinterface
letlongnativenewnull
packageprivateprotectedpublicreturn
shortstaticsuperswitchsynchronized
thisthrowthrowstransienttrue
trytypeofvarvoidvolatile
whilewithyield 

Following are the name of JS built-in objects, properties, and methods:

ArrayDateevalfunctionhasOwnProperty
InfinityisFiniteisNaNisPrototypeOflength
MathNaNnameNumberObject
prototypeStringtoStringundefinedvalueOf

Some Java objects and properties are also used in JavaScript.

getClassjavaJavaArrayjavaClassJavaObjectJavaPackage

JavaScript can also be used in many other applications. In HTML you must avoid using the name of HTML and Windows objects and properties

alertallanchoranchorsarea
assignblurbuttoncheckboxclearInterval
clearTimeoutclientInformationcloseclosedconfirm
constructorcryptodecodeURIdecodeURIComponentdefaultStatus
documentelementelementsembedembeds
encodeURIencodeURIComponentescapeeventfileUpload
focusformformsframeinnerHeight
innerWidthlayerlayerslinklocation
mimeTypesnavigatenavigatorframesframeRate
hiddenhistoryimageimagesoffscreenBuffering
openopeneroptionouterHeightouterWidth
packagespageXOffsetpageYOffsetparentparseFloat
parseIntpasswordpkcs11pluginprompt
propertyIsEnumradioresetscreenXscreenY
scrollsecureselectselfsetInterval
setTimeoutstatussubmittainttext
textareatopunescapeuntaintwindow

In addition you should avoid using the name of all HTML event handlers.

onbluronclickonerroronfocus
onkeydownonkeypressonkeyuponmouseover
onloadonmouseuponmousedownonsubmit

Optional Semicolon

Semicolons are used in JavaScript to separate statements from each other. But you can also omit the semicolon between two statements if those statements are written on separate lines.

Right :x = 7                     AND      x = 7;                AND x = 3; z = 7;

z = 3;                                   z = 3;

Since the two statements appear on separate line, line break is sufficient to tell these are two different statements. Semicolon before the line break is optional.

Wrong:x=7 z = 3;

Here, both statements are on same line but there is no way to differentiate between them. Therefore, a semicolon after first statement is required here.

By | 2015-04-10T05:54:23+00:00 April 10th, 2015|JavaScript|0 Comments

About the Author:

Leave A Comment