console.log("Hello, World!");
//dynamic properties
/*let value1= 10;
console.log(typeof(value1));  //number
let str="dinesh";                
console.log(typeof(str)); //string
let bool =true;
console.log(typeof(bool)); //Boolean
let define;
console.log(typeof(define));//undefined
let nullFine=null;
console.log(nullFine);     //null

let objectValue= { name:"dineshkumar" };
console.log(typeof(objectValue)); //referencr type is object.

let array = ['red','green','blue'];
console.log(array instanceof Array); //Array

let a=10;
let b=a;             //coping the value
b=20;           
console.log(a);
console.log(b);

let x = {name:'dinesh'};
let y = x             //coping th object value
y.name = 'david';
console.log(x.name);
console.log(y.name);

const arrayValue = ["dinesh","alan", "nowsik","benwin"];
const copyValue =[];
for(let i=0;i<arrayValue.length;i++){
  copyValue[i] = arrayValue[i];         //coping the array value1
}
console.log(copyValue);

const higherValue = (value1,value2,value3) =>{ // parameter passing
  let largeValue;
  if(value1 > value2 && value1 > value3){
    largeValue = value1;
  }
  else if(value2 > value1 && value2  > value3 ){
    largeValue = value2;
  }
  else{
    largeValue= value3;
  }
  return largeValue;
}
console.log(higherValue(4,50,6));


 function sumAll() {
  let sum=0;
  let inc;
  for(inc=0;inc<arguments.length;inc++) //arguments passing 
  {
    sum += arguments[inc];    
  }
  return sum;
  
}
console.log(sumAll(1,2,3,4,5,6,7,8,9));

function buildUrl(){
  let qs = "the value";
  with(location)            //with statement
  {
  let url = href + qs;   
  }
  return url;
}
console.log(buildUrl());
*/
const handlingBlock = () => {  //try-catch block
  let x=2;
try{
  x=x+y;
}
catch(err){
 console.log(err);  
}
}
handlingBlock();

if(true){
  var color ="red";
}
console.log(color);

for(var i=0;i < 10; i++){
// doSomething(i);
}
console.log(i);    //no Block level scope with var

var a=10;    //global variable
function functionA(){    //functionA Execution context
  console.log("aFunction");
  function functionB(){
    console.log("bFunction");
  }
  functionB();     //functionB Execution context
  
}
functionA();
console.log(a); //Global execution context
 

NodeJS Online Compiler

Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json.

About NodeJS

Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.

Key features

  • Built on Google chrome's javascript engine V8 and is pretty fast.
  • Node.js was developed by Ryan Dahl in 2009.
  • Server-side platform for building fast and scalable applications.
  • Node.js is Asynchronous, event-driven and works on single-thread model thus eliminating the dis-advantages of multi-thread model.
  • Supports various platforms like Windows, Linux, MacOS etc.
  • Provides rich library of java script modules which simplifies the development efforts.
  • Released under MIT license.

Express Framework

Express is one of the most popular web application framework in the NodeJS echosystem.

  • Pretty fast
  • Minimalist
  • Unopinionated
  • Very flexible

Syntax help

Examples

Using Moment

let moment = require('moment');

console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));

Using Lodash

const _ = require("lodash");

let colors = ['blue', 'green', 'yellow', 'red'];

let firstElement = _.first(colors);
let lastElement = _.last(colors);

console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);

Libraries supported

Following are the libraries supported by OneCompiler's NodeJS compiler.

  • lodash
  • moment
  • underscore
  • uuid
  • ejs
  • md5
  • url