“Variabel dalam JS” Kode Jawaban

cara mengubah nilai variabel dalam javascript

var variable = 10;

function start() {
  variable = 20;
}
console.log(variable + 20);

// Answer will be 40 since the variable was changed in the function
Helpless Hornet

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

Variabel 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 di JS

I love you
Comfortable Cottonmouth

Variabel JavaScript

var a;                          // variable
var b = "init";                 // string
var c = "Hi" + " " + "Joe";     // = "Hi Joe"
var d = 1 + 2 + "3";            // = "33"
var e = [2,3,5,8];              // array
var f = false;                  // boolean
var g = /()/;                   // RegEx
var h = function(){};           // function object
const PI = 3.14;                // constant
var a = 1, b = 2, c = a + b;    // one line
let z = 'zzz';                  // block scope local variable
Misty Manatee

Variabel dalam JS

var name = ""
Grumpy Goat

Jawaban yang mirip dengan “Variabel dalam JS”

Pertanyaan yang mirip dengan “Variabel dalam JS”

Lebih banyak jawaban terkait untuk “Variabel dalam JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya