Javascript is one of the most widely used programming language as it is completely supported by all the browsers and to achieve various tasks it is essential for webpage designers to learn this language. You can find lots of websites dedicated for learning Javascript but in these sessions we shall learn the implementation and real-world programming issues. We shall put much emphasis on what is right and how it is to be implemented rather than describing the syntax of javascript.

 

Let’s Begin

Case Sensitivity

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

However, HTML is not caste sensitive i.e. you can use the tags like <DIV> as <div> or <Div> without any difference between them

Unicode Support in Javascript

Javascript supports Unicode characters and they can be very easily be made as string objects like for example if you wish to write “café” in the string it is perfectly normal and you can easily declare a varible like this

var str = “café”;

or

var str = “caf\u00e9”

Above you can see \u00e9 code, this is known as unicode escape sequence. You can use \u followed by the unicode character code which can be easily found in the Windows Character Map utility.

Comments

JavaScript supports two styles of comments. Any text between a // and the end of a line is treated as a comment and is ignored by JavaScript. Any text between the characters /* and */ is also treated as a comment; these comments may span multiple lines but may not be nested. The following lines of code are all legal JavaScript comments:

// This is a single-line comment.
/* This is also a comment */ // and here is another comment.
/*
* This is yet another comment.
* It has multiple lines.
*/

Objects

In Javascript everything is an object

1.2  => Number Object

8 => Number Object

“cafe” => String Object

true => Boolean Object

/javacript/i => Regular Expression “regex” Object

null => No Object

function(){} => Function Object

Identifiers & Reserved Words

An identifier is simply a name. In JavaScript, identifiers are used to name variables and functions and to provide labels for certain loops in JavaScript code. A JavaScript identifier must begin with a letter, an underscore (_), or a dollar sign ($). Subsequent characters can be letters, digits, underscores, or dollar signs. (Digits are not allowed as the first character so that JavaScript can easily distinguish identifiers from numbers) For Example

i

m_va_n
v3

_myvar

$myvar

Like any language, JavaScript reserves certain identifiers for use by the language itself. These “reserved words” cannot be used as regular identifiers. They are listed below.

break, delete, function, return, typeof, case, do, if, switch, var, catch, else, in, this, void, continue, false, instanceof, throw, while, debugger, finally, new, true, with, default, for, null, try,

class, const, enum, export, extends, import, super, implements, let, private, public, yield, interface, package, protected, static,abstract, double, goto, native, static,boolean, enum, implements, package, super,

byte, export, import, private, synchronized,char, extends, int, protected, throws, class, final, interface, public, transient, const, float, long, short, volatile, arguments, encodeURI, Infinity, Number, RegExp,

Array, encodeURIComponent, isFinite, Object, String, Boolean, Error, isNaN, parseFloat, SyntaxError,Date, eval, JSON, parseInt, TypeError,decodeURI, EvalError, Math, RangeError, undefined,

decodeURIComponent ,Function, NaN, ReferenceError, URIError.

 

Optional Semicolon

Javascript doesn’t need semicolon as a separator between statements, however we strongly recommend on using the semicolon to keep code clean. Line break is considered as statement break.

Here are few examples that can lead to misinterpretations

 

return

true;

The above code actually means “return; true;” so it will never return a true value.

x

++

y

The above code means x; ++y;  and not as x++; y;

 

Conclusion

Here we conclude our basics chapter. I tried to keep it as short as possible and give you a quick look at the important aspects of the language.

 

Learning Javascript – Chapter 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.