TECNOLOGIE WEB BASE
Javascript (Node.js):
elementi di base
Programmi sincroni e asincroni
Programmi sincroni
Una istruzione viene
eseguita solo dopo che è
terminata l’esecuzione
dell’istruzione precedente.
Programmi asincroni
Una istruzione può essere
eseguita prima che sia
terminata l’esecuzione
dell’istruzione precedente.
PYTHON
JAVASCRIPT
Nella interrelazione
con il DOM o con un
server
Javascript e Node.js
Node.js è un versione di javascript che può
essere eseguita dal server.
Per fare i primi passi in javascript, utilizzeremo
la versione node.js eseguita da server che, non
interagendo con il dom, non pone problemi di
esecuzione asincrona delle istruzioni.
var MESS
MESS= 'Hello World!';
VARIABILI
Javascript
Assegnazione
Python
Assegnazione
MESS=’Hello World’
dichiarazione
STRINGHE
Javascript
(string/ ‘’)
Python
(str)
var STR, STR1, STR2;
STR1=’Hello ’;
STR2=’world’;
STR =STR1+STR2;
STR.replace(‘Hello’,’Wonderfull’);
STR.lenght
typeof STR
STR.constructor()
STR1=’Hello ’;
STR2=’world’;
STR =STR1+STR2;
STR.replace(‘Hello’,’Wonderfull’);
len(STR)
type(STR)
Numeri
Javascript
(number/ 0)
Python
(int, float)
var NUM1, NUM2, NUM3;
NUM1=5;
NUM2=3.66;
NUM3=NUM1/NUM2;
NUM3.toFixed()
NUM3.toString()
typeof NUM3
NUM3.constructor()
NUM1=5;
NUM2=3.66;
NUM3=NUM1/NUM2;
int(round(NUM3,0))
str(NUM3)
type(NUM3)
Liste
Javascript
(object/ [ ])
Python
(list)
var LIS1, LIS2;
LIS1=[10,12,52,64,37,'a','b']
LIS2=[7,55,44]
LIS1+LIS2 string
LIS1*2 NaN
LIS1.concat(LIS2)
LIS1[0]
LIS1[5]
LIS1.slice(0,3)
typeof LIS1
LIS1.constructor()
LIS1=[10,12,52,64,37,'a','b']
LIS2=[7,55,44]
LIS1+LIS2 concatenazione
LIS1*2 LIS1+LIS1
LIS1+LIS2
LIS1[0]
LIS1[5]
LIS1[0:3]
type(LIS1)
Dizionari
Javascript
(object/ { })
Python
(dict)
var DIZ1, DIZ2;
DIZ1={'DEU':100, 'FRA':150 }
DIZ2={'ITA':50, 'ESP':500}
DIZ1[‘DEU’]
typeof DIZ1
DIZ1.constructor()
DIZ1={'DEU':100, 'FRA':150 }
DIZ2={'ITA':50, 'ESP':500}
DIZ1[‘DEU’]
type(DIZ1)
Blocco if
Javascript Python
var V1=20;
var RIS='';
if (V1<5) {RIS="V1 is <=5";}
else if (V1<15) {RIS="V1 is ranging 5-15";}
else {RIS="V1 is >=15";}
V1=20
if V1<5: RIS="V1 is <=5"
elif V1<15: RIS="V1 is ranging 5-15"
else: RIS="V1 is >=15";
Ciclo for
Javascript Python
var text=''
for (var i=0; i<10; i=i+1) {text = text +" " + i}
text=''
for i in range(0,10):
text = text +" " + str(i)
Ciclo while
Javascript Python
var i=0;
var text=''
while (i < 10) {text = text +" " + i; i=i+1;}
text=''
i=0
while True:
text = text +" " + str(i)
i=i+1
if i >= 10:
break
TECNOLOGIE WEB BASE
Javascript e Node.js:
oggetti globali
Oggetti globali javascript e Node.js
javascript Node.js
console console
E’ un oggetto globale che fornisce una interfaccia di debug.
console.log(‘......’) console.log(‘.....’)
Scrive la stringa passata come argomento nello standard output
L’oggetto console di Node.js non replica perfettamente l’oggetto console dei principali
browser. Ad esempio non ha implementato il metodo .clean() per cancellare il
contenuto dello standard output
Moduli base Node.js e python
Node.js Python
os sys path process os
var os=require('os');
var sys=require('sys');
var path=require('path');
import os
import sys
sys
process.env.PATH sys.path
path.dirname()
path.join('...','...’')
process.cwd();
os.hostname()
os.arch()
process.pid
os.path.curdir
os.sys.join(‘......’, ‘.......’)
os.path.abspath(os.path.curdir)
os.uname()
os.getpid()
LEZIONE 1..
www.fordatascientist.org
D00-Web-JsBase
D10-Nodejs-Introduction
TECNOLOGIE WEB BASE
Funzioni
Funzioni: tramite dichiarazione
Javascript Python
function Sum(N1,N2){
// This function does sum of two number
console.log('Sum is running')
S=N1+N2;
return S
}
var N;
N=Sum(12,74);
def Sum(N1,N2):
‘’’This function does sum of two number’’’
print('Sum is running')
S=N1+N2;
return S
N=Sum(12,74);
Funzioni: tramite assegnazione
Javascript
var Sum= function (N1,N2){
// This function does sum of two number
console.log('Sum is running')
S=N1+N2;
return S
}
var N;
N=Sum(12,74);
dal punto di vista funzionale, la creazione di
una funzione tramite dichiarazione è
equivalente alla creazione tramite
assegnazione. La creazione tramite
assegnazione può essere utile in termini di
“chiarezza del codice” quando si vuole
utilizzare la funzione come input di un’altra
funzione. Ad esempio
var SAY=function(WORD)
{console.log(WORD);}
function Exec(someF, VAL)
{someF(VAL);}
Exec(SAY, "Hello");
Funzioni: dichiarazione e assegnazione
Le funzioni create tramite dichiarazione sono caricate in
memoria centrale prima di processare le altre istruzioni.
Una funzione creata tramite dichiarazione può essere
posizionata anche dopo la sua chiamata.
Scope delle variabili interne ad una funzione
Javascript Python
possono essere sia locali
che globali. Sono locali se
sono create tramite il
costruttore ‘var’. Sono
globali se sono create
tramite una semplice
assegnazione.
una variabile creata
all’interno di una funzione
è sempre locale, a meno
che essa prima di essere
creata non sia stata
definita come ‘global’
LEZIONE 1..
www.fordatascientist.org
D00-Web-JsBase
D12-Nodejs-Function
CONTATTI TELEFONO
051 22 35 20
EMAIL
WORKSHOP@VICEM.IT
var
number
typeof
string
object
[ ]
{ }
constructor

More Related Content

PDF
Web base-03-js-numeri stringearray
PPTX
J huery
PDF
Comunicazione tra procesi Linux
PDF
Espressioni regolari da 0 a esperti
PDF
PHP on the desktop
PDF
Gestione delle dipendenze con Composer
PDF
Web base - CSS e selettori
PDF
Web base - HTML
Web base-03-js-numeri stringearray
J huery
Comunicazione tra procesi Linux
Espressioni regolari da 0 a esperti
PHP on the desktop
Gestione delle dipendenze con Composer
Web base - CSS e selettori
Web base - HTML

Viewers also liked (19)

PDF
Python base lezione 5
PDF
Python base lezione1
PDF
ForDataScientist - Python matplotlib
PDF
Python base lezione 2
PDF
Python base lezione 3
PDF
Python base lezione 4
PDF
ForDataScientist - Python advanced data
PDF
Web base - SVG
PDF
WEB BASE - Una visione d'insieme delle tecnologie web
PDF
Oracle ebs leave management system
PDF
ForDataScientist - Python base parte2
PDF
Dizajn za Facebook stranice - Tanja Dujmović
PPTX
Celulita
PPT
Sales Presentation 2-12-2016 TM
PDF
Climate Change White Paper_Published
PDF
Requsition user menual
PDF
Don Xem Quan Ao Thoi Trang Nu Moi Nhat Tai Tyty
PDF
erald kolici portfolio
PDF
Fordatascientist - Tecnologie Web base
Python base lezione 5
Python base lezione1
ForDataScientist - Python matplotlib
Python base lezione 2
Python base lezione 3
Python base lezione 4
ForDataScientist - Python advanced data
Web base - SVG
WEB BASE - Una visione d'insieme delle tecnologie web
Oracle ebs leave management system
ForDataScientist - Python base parte2
Dizajn za Facebook stranice - Tanja Dujmović
Celulita
Sales Presentation 2-12-2016 TM
Climate Change White Paper_Published
Requsition user menual
Don Xem Quan Ao Thoi Trang Nu Moi Nhat Tai Tyty
erald kolici portfolio
Fordatascientist - Tecnologie Web base
Ad

Similar to Web base - Javascript (Node.js): Elementi di base (20)

PDF
Corso base di Tecnologie WEB - Primi passi in javascript
PPT
node.js e Postgresql
PDF
Introduzione a node.js
PDF
Introduzione a Node.js
PPT
Applicazioni native in java
PPTX
Node js dev day napoli 2016
PDF
Node.js - Server Side Javascript
PPTX
06 Android - lavorare in background
PDF
Sviluppo web dall'antichità all'avanguardia e ritorno
PPT
PDF
Techbar nodejs+mongodb+mongoose
ODP
Concurrency
PPTX
Andrea Ceroni - Alexa, please deploy my Azure architecture - Codemotion Rome ...
PPTX
ASP.NET MVC 6 - uno sguardo al futuro
PDF
Corso Java 2 - AVANZATO
PDF
Drupal Day 2011 - Node.js e Drupal
PPT
Primo Incontro Con Scala
PDF
Tech Webinar: Test e2e per AngularJS e non solo
PPT
Progettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
PDF
Come Javascript ha cambiato il CSS
Corso base di Tecnologie WEB - Primi passi in javascript
node.js e Postgresql
Introduzione a node.js
Introduzione a Node.js
Applicazioni native in java
Node js dev day napoli 2016
Node.js - Server Side Javascript
06 Android - lavorare in background
Sviluppo web dall'antichità all'avanguardia e ritorno
Techbar nodejs+mongodb+mongoose
Concurrency
Andrea Ceroni - Alexa, please deploy my Azure architecture - Codemotion Rome ...
ASP.NET MVC 6 - uno sguardo al futuro
Corso Java 2 - AVANZATO
Drupal Day 2011 - Node.js e Drupal
Primo Incontro Con Scala
Tech Webinar: Test e2e per AngularJS e non solo
Progettazione e sviluppo di applicazioni web 2.0 con PHP e Ajax
Come Javascript ha cambiato il CSS
Ad

More from Annalisa Vignoli (6)

PDF
Presentazione Corsi FDS
PPTX
Presentazione Ulisse - Rame
PPTX
Presentazione Ulisse - Acciaio
PDF
Fordascientist - Python reportlab
PDF
ForDataScientist - Python base parte1
PDF
abstract_tesi
Presentazione Corsi FDS
Presentazione Ulisse - Rame
Presentazione Ulisse - Acciaio
Fordascientist - Python reportlab
ForDataScientist - Python base parte1
abstract_tesi

Recently uploaded (8)

PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PDF
Presentazione di Chimica sui Coloranti Alimentari
PPTX
San Giovanni Eudes, 1601 – 1680, sacerdote e fondatore francese.pptx
PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PPTX
Santa Rosa da Lima, Vergine, Penitente, Terziaria Domenicana 1586-1617.pptx
PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PDF
Presentazione educazione finanziaria e informazione.pdf
PDF
Critico_o_creativo_Approcci_al_testo_let.pdf
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
Presentazione di Chimica sui Coloranti Alimentari
San Giovanni Eudes, 1601 – 1680, sacerdote e fondatore francese.pptx
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
Santa Rosa da Lima, Vergine, Penitente, Terziaria Domenicana 1586-1617.pptx
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
Presentazione educazione finanziaria e informazione.pdf
Critico_o_creativo_Approcci_al_testo_let.pdf

Web base - Javascript (Node.js): Elementi di base

  • 1. TECNOLOGIE WEB BASE Javascript (Node.js): elementi di base
  • 2. Programmi sincroni e asincroni Programmi sincroni Una istruzione viene eseguita solo dopo che è terminata l’esecuzione dell’istruzione precedente. Programmi asincroni Una istruzione può essere eseguita prima che sia terminata l’esecuzione dell’istruzione precedente. PYTHON JAVASCRIPT Nella interrelazione con il DOM o con un server
  • 3. Javascript e Node.js Node.js è un versione di javascript che può essere eseguita dal server. Per fare i primi passi in javascript, utilizzeremo la versione node.js eseguita da server che, non interagendo con il dom, non pone problemi di esecuzione asincrona delle istruzioni.
  • 4. var MESS MESS= 'Hello World!'; VARIABILI Javascript Assegnazione Python Assegnazione MESS=’Hello World’ dichiarazione
  • 5. STRINGHE Javascript (string/ ‘’) Python (str) var STR, STR1, STR2; STR1=’Hello ’; STR2=’world’; STR =STR1+STR2; STR.replace(‘Hello’,’Wonderfull’); STR.lenght typeof STR STR.constructor() STR1=’Hello ’; STR2=’world’; STR =STR1+STR2; STR.replace(‘Hello’,’Wonderfull’); len(STR) type(STR)
  • 6. Numeri Javascript (number/ 0) Python (int, float) var NUM1, NUM2, NUM3; NUM1=5; NUM2=3.66; NUM3=NUM1/NUM2; NUM3.toFixed() NUM3.toString() typeof NUM3 NUM3.constructor() NUM1=5; NUM2=3.66; NUM3=NUM1/NUM2; int(round(NUM3,0)) str(NUM3) type(NUM3)
  • 7. Liste Javascript (object/ [ ]) Python (list) var LIS1, LIS2; LIS1=[10,12,52,64,37,'a','b'] LIS2=[7,55,44] LIS1+LIS2 string LIS1*2 NaN LIS1.concat(LIS2) LIS1[0] LIS1[5] LIS1.slice(0,3) typeof LIS1 LIS1.constructor() LIS1=[10,12,52,64,37,'a','b'] LIS2=[7,55,44] LIS1+LIS2 concatenazione LIS1*2 LIS1+LIS1 LIS1+LIS2 LIS1[0] LIS1[5] LIS1[0:3] type(LIS1)
  • 8. Dizionari Javascript (object/ { }) Python (dict) var DIZ1, DIZ2; DIZ1={'DEU':100, 'FRA':150 } DIZ2={'ITA':50, 'ESP':500} DIZ1[‘DEU’] typeof DIZ1 DIZ1.constructor() DIZ1={'DEU':100, 'FRA':150 } DIZ2={'ITA':50, 'ESP':500} DIZ1[‘DEU’] type(DIZ1)
  • 9. Blocco if Javascript Python var V1=20; var RIS=''; if (V1<5) {RIS="V1 is <=5";} else if (V1<15) {RIS="V1 is ranging 5-15";} else {RIS="V1 is >=15";} V1=20 if V1<5: RIS="V1 is <=5" elif V1<15: RIS="V1 is ranging 5-15" else: RIS="V1 is >=15";
  • 10. Ciclo for Javascript Python var text='' for (var i=0; i<10; i=i+1) {text = text +" " + i} text='' for i in range(0,10): text = text +" " + str(i)
  • 11. Ciclo while Javascript Python var i=0; var text='' while (i < 10) {text = text +" " + i; i=i+1;} text='' i=0 while True: text = text +" " + str(i) i=i+1 if i >= 10: break
  • 12. TECNOLOGIE WEB BASE Javascript e Node.js: oggetti globali
  • 13. Oggetti globali javascript e Node.js javascript Node.js console console E’ un oggetto globale che fornisce una interfaccia di debug. console.log(‘......’) console.log(‘.....’) Scrive la stringa passata come argomento nello standard output L’oggetto console di Node.js non replica perfettamente l’oggetto console dei principali browser. Ad esempio non ha implementato il metodo .clean() per cancellare il contenuto dello standard output
  • 14. Moduli base Node.js e python Node.js Python os sys path process os var os=require('os'); var sys=require('sys'); var path=require('path'); import os import sys sys process.env.PATH sys.path path.dirname() path.join('...','...’') process.cwd(); os.hostname() os.arch() process.pid os.path.curdir os.sys.join(‘......’, ‘.......’) os.path.abspath(os.path.curdir) os.uname() os.getpid()
  • 17. Funzioni: tramite dichiarazione Javascript Python function Sum(N1,N2){ // This function does sum of two number console.log('Sum is running') S=N1+N2; return S } var N; N=Sum(12,74); def Sum(N1,N2): ‘’’This function does sum of two number’’’ print('Sum is running') S=N1+N2; return S N=Sum(12,74);
  • 18. Funzioni: tramite assegnazione Javascript var Sum= function (N1,N2){ // This function does sum of two number console.log('Sum is running') S=N1+N2; return S } var N; N=Sum(12,74); dal punto di vista funzionale, la creazione di una funzione tramite dichiarazione è equivalente alla creazione tramite assegnazione. La creazione tramite assegnazione può essere utile in termini di “chiarezza del codice” quando si vuole utilizzare la funzione come input di un’altra funzione. Ad esempio var SAY=function(WORD) {console.log(WORD);} function Exec(someF, VAL) {someF(VAL);} Exec(SAY, "Hello");
  • 19. Funzioni: dichiarazione e assegnazione Le funzioni create tramite dichiarazione sono caricate in memoria centrale prima di processare le altre istruzioni. Una funzione creata tramite dichiarazione può essere posizionata anche dopo la sua chiamata.
  • 20. Scope delle variabili interne ad una funzione Javascript Python possono essere sia locali che globali. Sono locali se sono create tramite il costruttore ‘var’. Sono globali se sono create tramite una semplice assegnazione. una variabile creata all’interno di una funzione è sempre locale, a meno che essa prima di essere creata non sia stata definita come ‘global’