Learn JavaScript Syntax





Part 1


Javascript syntax is based on Java syntax.


It is a set of rules.


This tutorial cover the syntax basics that will allow you to code with javascript (the text in grey is a comment)


Code Example:

                    
                # declare variables
                var a, b, c,
                
# assign values
a = 4 ; b = 6;

# c = 10
c = b + a;
                 
            








Part 2


JavaScript Literals




Numbers


You can type numbers with decimals or without.


Code Example:

                    
               100
24.3
                 
            
Try yourself >>






Strings


You can type strings with double or single quotes.


Code Example:

                    
               "Jake"
'Jake'
                 
            
Try yourself >>








Part 3


JavaScript Values


There are two types of values:


variable values and Fixed values


Variable values are called variables.


Fixed values are called literals.





Part 4


JavaScript Operators


to compute values, Javascript uses operators such: ( / * + - )


Visit our Javascript Arithmetic Opeartors reference to learn the full guide of Javascript Arithmetic operators



Code Example:

( 40 - 10 ) * 2

Try yourself >>






to assign values, Javascript uses assignment operators: ( = )


Visit our Javascript Assignment Opeartors reference to learn the full guide of Javascript Assignment operators


Code Example:

var y, x,
y = 4 ;
x = 2 ;

Try yourself >>






Part 5


JavaScript Expressions


When we combine variables, values, and operators, it is called evaluation


For example, 2 * 5 evaluates to 10:



Code Example:

2 * 5

Try yourself >>


Expressions can also contain variable values:


Code Example:

z * 2

Try yourself >>


tip: You can also use numbers or strings, so "Bruce" + "Clynt" evaluates "Bruce Clynt"






Part 6


JavaScript Variables


Variable is used to store data value.


Use the var keyword to declare variable.


You can also use = sign to assign values to variables.


Next example shows how Z is defined as var (variable), then we give Z which is now variable the value of 10


Code Example:

var z;
z = 10;

Try yourself >>



Visit our Javascript Variables reference to learn the full guide of Javascript Variables







Part 7


JavaScript Comments


Some Javascript statements are not "Executed"


Any of these three /* // */ signs are used to write comment that the computer will not execute and ignore.



Code Example:

var z = 10 ; // This will be executed
// var x = 11; this will NOT be executed

Try yourself >>




Visit our Javascript Comments reference to learn the full guide of Javascript Comments




Part 8


JavaScript Keywords


Keywords order the browser to create variables, the var in the example below is keyword:



Code Example:

var z, x;
x = 2 + 3 ;
z = x * 2 ;

Try yourself >>




We can't use some of the keywords, Visit our Javascript Reserved words reference to learn the full guide of Javascript Reserved words






Part 9


JavaScript Identifiers


Identifier is used to name variables, keywords, labels, and functions.


The first character must be a letter, or an underscore or a dollar sign



tip: You can't type numbers as first character of identifier.


tip: Identifiers are case sensitive, David and david, are not the same variables.



With us, you can learn Javascript and Web development, our main goal is to allow students to learn Javascript and other online coding courses free and easily.



Navigation