Primeros Pasos. Un Ejemplo Simple

[~/src/javascript/node.js/hector_correa_introduction_to_node(master)]$ cat -n hello_world.js 
     1  console.log("Hello world!");
     2  a = [ 'batman', 'robin'];
     3  a.push("superman");
     4  console.log(a);
     5  h = { name: 'jane rodriguez-leon', department: 'IT' };
     6  console.log(h);
     7  console.log(h['name']);

[~/src/javascript/node.js/hector_correa_introduction_to_node(master)]$ node hello_world.js 
Hello world!
[ 'batman', 'robin', 'superman' ]
{ name: 'jane rodriguez-leon', department: 'IT' }
jane rodriguez-leon

[~/Dropbox/academica/ETSII/grado/LPP/LPPbook]$ node
> .help
.break  Sometimes you get stuck, this gets you out
.clear  Alias for .break
.exit Exit the repl
.help Show repl options
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file

> console.log("Hello world!")
Hello world!
undefined
> a = [ 'batman', 'robin']
[ 'batman', 'robin' ]
> a.push("superman")
3
> a
[ 'batman', 'robin', 'superman' ]
> h = { name: 'jane rodriguez-leon', department: 'IT' }
{ name: 'jane rodriguez-leon',
  department: 'IT' }
> h['name']
'jane rodriguez-leon'
> 4+2
6
> _    # ultimo valor evaluado
6
> _+1
7
> 
> a = [1,2,3]
[ 1, 2, 3 ]
> a.forEach(function(e) { console.log(e); })
1
2
3
> a.forEach(function(v) {
... console.log(v
..... .break
> a
[ 1, 2, 3 ]
> .exit # también CTRL-D en Unix
[~/Dropbox/academica/ETSII/grado/LPP/LPPbook]$

Casiano Rodríguez León
2013-04-23