javascript-dasar-variabelScope

Run Settings
LanguageJavaScript
Language Version
Run Command
// global variable, dapat diakses pada parent() dan child() const a = 'a'; function parent() { // local variable, dapat diakses pada parent() dan child(), tetapi tidak dapat diakses diluar dari fungsi tersebut. const b = 'b'; function child() { // local varible, dapat diakses hanya pada fungsi child(). const c = 'c'; } } // Coba variable scope // ================================= // Tanpa mendeklarasi variable total function multiply(num) { total = num * num; return total; } let total = 9; let number = multiply(10); console.log(total) /* output 400 */ // ================================== // mendeklarasi variable total function multiply(num) { let total = num * num; return total; } let total = 9; let number = multiply(10); console.log(total) // output // 9
Editor Settings
Theme
Key bindings
Full width
Lines