“Variables JS” Réponses codées

Variable JS

let x;
x = 102;
Rick Astley

js var

var x = 0;

function f() {
  var x = y = 1; // x è dichiarata localmente. y invece no!
}
f();

console.log(x, y); // Genera un ReferenceError in strict mode (y non è definita). 0, 1 altrimenti.
// In modalità non-strict mode:
// x è la globale come si ci aspettava
// però, y è uscita fuori dalla funzione!
DevLorenz02

Variables JavaScript

// here are the ways to define variables
var x = "hi"; // for global variables
let x = "hi"; // for block-scoped variables
const x = "hi"; // for block-scoped variables which can not be reassigned
The Cat Coder

var javascript

var is a keyword to define the varible in js but as of es-6 we, use let and const keywords for the same
Xerothermic Xenomorph

Variables JS

// Can be a number
var myVar = 21
//Can be a string
var myVar2 = "string"
// Used in a function
function printVar(parvar) {
  print(parvar);
}

printVar(myVar2);
// prints "string"
printVar(myVar);
// prints 21
Disgusting Chicken

Variables JS

// 3 ways to create

var mrVariable = 'x'; // You can set it to to a string ( '' ) or no. ( 0 ). It 
// is globally defined

let myVariaible2 = 'y'; // You can set it to string or no. let is block scoped

const myVariable = 'z'; // It is block scoped, can be a string or no. and can't 
//be reassigned
Annoying Antelope

Réponses similaires à “Variables JS”

Questions similaires à “Variables JS”

Plus de réponses similaires à “Variables JS” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code