JavaScript
In this tutorial we will learn about JavaScript Basic Concepts.
JavaScript borrows most of its syntax from languages like C/C++, Java, Python etc.
JavaScript is case-sensitive language. This means lower case letters and upper case letters are treated differently. For example, name
and Name
are different even though they are the same word.
Programs are list of instructions that are executed by the computer. JavaScript programs are instructions that are executed by the web browser.
JavaScript statements are the instructions written by a programmer.
Every instruction in JavaScript ends with a semicolon ;
In the following example we have an instruction that will print "Hello World" in the browser console.
console.log("Hello World");
The smallest individual unit in a program is called token.
List of JavaScript tokens.
Reserved keywords are words that carry a special meaning and must not be used to name variables and functions.
Click here for JavaScript Variables.
Click here for JavaScript Functions.
Following are some of the commonly used JavaScript reserved keywords.
break | case | const | continue |
default | delete | do | else |
false | final | for | function |
if | instanceof | new | null |
return | static | switch | this |
true | typeof | var | while |
Identifiers are sequence of characters that are used to name the variables, functions etc.
Characters of an identifier can be a letter, digit, dollar sign and underscore. The first character cannot be a digit.
Following are valid identifiers.
name
_name
name$
student01
Following are invalid identifiers.
01student
student-name
student+name
Following are the list of punctuators that we use in JavaScript.
= | < | > | == | <= | >= | === |
! | != | !== | + | - | * | / |
, | . | % | ~ | ? | : | ; |
& | && | | | || | ++ | -- | ^ |
&= | |= | %= | += | -= | *= | /= |
^= | << | >> | >>> | <<= | >>= | >>>= |
( | ) | [ | ] | { | } |
We use literals to represent value in JavaScript.
List of literals.
The value of the Null literal is null
. It represent null or empty.
The value of the Boolean literal are true
and false
. These are logical values.
We use Numeric literal to represent numbers or numerical value.
Following are the types of numerical values.
Decimal number are base 10 i.e., they consists of 10 digits 0 to 9.
Hexadecimal number are base 16 i.e., they consists of 10 digits 0 to 9 and 6 letters a to f. Upper case A to F is also used. Hex number start with 0x
and 0X
.
Example: 0xA is in hex form and its decimal equivalent is 10.
Click here for Hexadecimal to Decimal conversion tutorial.
Octal number are base 8 i.e., they consists of 8 digits 0 to 7. Octal number starts with 0
.
Example: 017 is in octal form and its decimal equivalent is 15.
Click here for Octal to Decimal conversion tutorial.
Strings are sequence of characters enclosed in double and single quote in JavaScript.
In the following example we have a string enclosed in double quote.
"Hello World"
In the following example we have a string enclosed in single quote.
'We are learning JavaScript.'
ADVERTISEMENT