JS Basics

Link JS file

    

<script src="main.js"></script>


    

Inline script

    

<script>
  console.log("Hello world");
</script>


    

Comments

    

// Single line comment


    
    

/*
  Multi-line
  comment
*/


    

Logging to the console

    

console.log("Hello world");


    

Variable

    

let a = 'hello world';


    
    

// Older syntax
var a = 'hello world';


    

Constant

    

const a = 'hello world';


    

Declare multiple variables

    

let a, b;


    
    

// Older syntax
var a, b;


    

Initialize multiple variables

    

let a = 'hello', b = 'world';


    
    

// Older syntax
var a = 'hello', b = 'world';