Javascript-basics

Last modified on March 05th, 2020 by DigitalIndiaInfo Team.


JavaScript Overview

Learn some important characteristics of JavaScript syntax in this section.

Character Set

JavaScript uses the Unicode character set and so allows almost all characters, punctuations, and symbols.

Case Sensitive

JavaScript is a case sensitive scripting language. It means functions, variables and keywords are case sensitive. For example, VAR is different from var, John is not equal to john.

String

String is a text in JavaScript. A text content must be enclosed in double or single quotation marks.

Example: string
<script>
    
                        "Hello World" //JavaScript string in double quotes
    
                        'Hello World' //JavaScript string in single quotes  
</script>

Number

JavaScript allows you to work with any kind of numbers like integer, float, hexadecimal etc. Number must NOT be wrapped in quotation marks.

Integer: 1000

Float: 10.2

Boolean

As in other languages, JavaScript also includes true or false as a boolean value.

Semicolon

JavaScript statements are separated by a semicolon. However, it is not mandatory to end every statement with a semicolon but it is recommended.

For example, JavaScript considers three different statements for following:

one = 1; two=2; three=3;

White space

JavaScript ignores multiple spaces and tabs.

The following statements are same.

Example: JavaScript ignores whitespaces
var one =1;
var one   =   1;
var one        =         1;

Comments

A comment is a single or multiple lines, which give some information about the current program. Comments are not for execution.

Write comment after double slashes // or write multiple lines of comments between/* and */

Example: code comment
var one =1; // this is a single line comment
/* this  
is multi line
comment*/
var two = 2;
var three = 3;

Keywords

Keywords are reserved words in JavaScript, which cannot be used as variable names or function names.

The following table lists some of the keywords used in JavaScript.

Keywords
var function if
else do while
for switch break
continue return try
catch finally debugger
case class this
default false true
in instanceOf typeOf
new null throw
void width delete
Points to Remember :
  1. JavaScript uses unicode characterset.
  2. JavaScript is case sensitive.
  3. JavaScript string must be enclosed in double quotation mark (") or single quotation mark (').
  4. JavaScript Number can store integer, float, hexadecimal value without enclosing it in quotation marks.
  5. JavaScript boolean value stores true or false.
  6. Every statement in JavaScript can be separated using semicolon (;). It is not mandatory but recommended to use semicolon at the end of each statement.
  7. JavaScript ignores multiple white spaces.
  8. A multi line comment can be wrapped between /* and */. Single line comment can start with //.
  9. JavaScript keywords are reserved words. Do not use them as variable or function names.


References :

  • www.tutorial.digitalindiainfo.com