ⴰⴼⵀⴰⵎ ⵏ ⵢⵉⵎⵓⴹⴰⵏ ⴷⴻⴳ ⵓⵙⴻⵍⴽⴻⵎ<ⴰ ⵉⴷ="ⴰⴼⵀⴰⵎ ⵏ ⵢⵉⵎⵓⴹⴰⵏⴷⴻⴳ-ⵓⵀⵉⵍ"></ⴰ>
ⴷ ⴰⵛⵓ ⵉ ⴷ ⴰⵎⴳⵉⵔⴻⴷ?<ⴰ ⵉⴷ="ⴷ ⴰⵛⵓⵜ-ⵓⵎⴱⵉⴷⴷ"></ⴰ>
ⵉⵎⵓⴹⴰⵏ ⴷ ⵉⴼⴻⵔⴷⵉⵙⴻⵏ ⵉⴳⴻⵊⴷⴰⵏⴻⵏ ⴷⴻⴳ ⵓⵙⴻⵍⴽⵉⵎ ⵉⵎⵉ ⵜⵜⵡⴰⵙⴻⵇⴷⴰⵛⴻⵏ ⵉ ⵓⵃⴻⵣⵣⴻⴱ ⵏ ⵢⵉⵙⴰⵍⵍⴻⵏ ⵉⵣⴻⵎⵔⴻⵏ ⴰⴷ ⵜⵜⵡⴰⵙⴻⵎⵍⴻⵏ ⵢⴻⵔⵏⴰ ⴰⴷ ⵜⵜⵡⴰⵃⴻⵔⵣⴻⵏ ⴷⴻⴳ ⵡⴰⵀⵉⵍ ⵏ ⵓⵙⴻⵍⴽⵉⵎ. ⵜⵜⴰⴽⴻⵏⴷ ⴰⴱⵔⵉⴷ ⵏ ⵓⵙⵎⴻⴽⵜⵉ ⵏ ⵢⵉⵙⴻⴼⴽⴰ ⵙ ⵢⵉⵙⴻⵎ ⵏ ⵓⵙⵎⴻⵍ, ⵙ ⵡⴰⵢⴰ, ⴰⵀⵉⵍⴻⵏ ⵜⵜⵡⴰⴼⴻⵀⵎⴻⵏ ⵓⴳⴰⵔ ⵉ ⵓⵎⴻⵖⵔⵉ ⴷ ⵢⵉⵎⴰⵏⵏⵏⴻⵖ. ⵅⴻⵎⵎⴻⵎ ⵖⴻⴼ ⵢⵉⵎⴻⴹⵇⴰⵏ ⴰⵎ ⵢⵉⴼⴻⵔⴷⵉⵙⴻⵏ ⵉ ⵢⴻⵜⵜⴰⵟⵟⴰⴼⴻⵏ ⵉⵙⴰⵍⴰⵏ. ⵉⵙⵡⵉⵏⵙⴻⵏ ⴽⴰⵏ ⴷ ⴰⵙⴻⴽⵛⴻⵎ ⵏ ⵜⵎⴻⵥⵔⵉⵡⵉⵏ ⴷ ⵓⵃⴻⵣⵣⴻⴱ ⵏ ⵢⵉⵙⴻⴼⴽⴰ ⴷⴻⴳ ⵜⵎⴻⵥⵔⵉⵡⵜ, ⵉⵣⴻⵎⵔⴻⵏ ⴰⴷ ⵜⵜⵡⴰⵙⵇⴻⴷⵛⴻⵏ ⵙⴰⴽⴽⵉⵏ ⴷⴻⴳ ⵡⴰⵀⵉⵍⵉⴽ.
ⴰⵙⴻⴽⵛⴻⵎ ⵏ ⵡⴰⵣⴰⵍⴻⵏ ⵉ ⵢⵉⵎⵓⴹⴰⵏ<ⴰ ⵉⴷ="ⴰⵙⴻⴽⵛⴻⵎ ⵏ ⵡⴰⵣⴰⵍⴻⵏⵉ ⵢⵉⵎⵓⴹⴰⵏ"></ⴰ>
ⴰⵙⵙⴻⵎⵔⴻⵙ ⵏ ⵢⵉⵙⴻⵎ ⵏ ⵢⵉⵎⴻⴹⵇⴰⵏ ⵢⴻⵣⵎⴻⵔ ⴰⴷ ⵢⵉⵍⵉ ⴷ ⴰⵢⴻⵏ ⵉⵅⵓⵚⵚⴻⵏ; ⵢⴻⵣⵎⴻⵔ ⴰⴷ ⵢⵉⵍⵉ ⴷ ⴰⵡⴻⵣⵖⵉ ⴰⴷ ⴷⵏⴰⴼ ⵉⵙⵎⴰⵡⴻⵏ ⵏ ⵢⵉⵎⴻⴹⵇⴰⵏ ⵉⴱⴰⵏⴻⵏ ⵢⴻⵔⵏⴰ ⵜⵜⵡⴰⵃⴻⵔⵣⴻⵏ. ⵎⴰⵛⴰ, ⵉⵍⴰⵇ ⴰⴷ ⵏⴻⵙⵙⴻⵎⵔⴻⵙ ⴰⵙⴻⴼⵀⴻⵎ ⴷ ⵓⵙⴼⴻⵀⴻⵎ ⵙ ⵜⵖⴰⵡⵍⴰ ⵎⵉ ⴰⵔⴰ ⴷⵏⴻⴼⴽ ⵉⵙⴻⵎ ⵏ ⵢⵉⵎⴻⴹⵇⴰⵏ. ⵛⴼⵓ ⴱⴻⵍⵍⵉ ⵡⵉⵢⴰⴹ, ⵓⵍⴰ ⴷ ⴽⴻⵞⵞ ⵙ ⵜⵉⵎⵎⴰⴷⵉⴽ, ⴰⴷ ⵃⵡⴰⴵⴻⵏ ⴰⴷ ⵖⵔⴻⵏ ⵢⴻⵔⵏⴰ ⴰⴷ ⴼⴻⵀⵎⴻⵏ ⴰⴽⴰⵔⴰⵎ. ⴰⵙⴻⵇⴷⴻⵛ ⵏ ⵢⵉⵙⵎⴰⵡⴻⵏ ⵉ ⴷⵢⴻⵙⴽⴰⵏⴰⵢⴻⵏ ⵙ ⵜⵖⴰⵡⵍⴰ ⵉⵙⵡⵉ ⵏ ⵓⵎⴳⵉⵔⴻⴷ ⴰⴷ ⵢⴻⵙⵙⵉⵡⴻⴹ ⴰⴷ ⵢⴻⵙⵙⵉⵡⴻⴹ ⵓⴹⵔⵉⵙⵉⴽ ⴰⴷ ⵜⵜⴻⵖⵔⴻⴹ ⵢⴻⵔⵏⴰ ⴰⴷ ⵜⵜⴻⵃⵔⴻⵣⴹ. ⴷⴻⴳ ⵓⵙⴻⵍⴽⵉⵎ, ⵜⴻⴼⴽⵉⴹ ⴰⵣⴰⵍ ⵉ ⵢⵉⵎⴻⴹⵇⴰⵏ ⵙ ⵓⵙⴻⵇⴷⴻⵛ ⵏ ⵜⵎⴻⵥⴷⵉⵜ =
, ⵙ ⵢⵉⵙⴻⵎ ⵏ ⵓⵎⵙⴻⴹⵔⵓ ⴷⴻⴳ ⵓⵣⴻⵍⵎⴰⴹ ⴷ ⵡⴰⵣⴰⵍ ⴷⴻⴳ ⵢⵉⴷⵉⵙ ⴰⵢⴻⴼⴼⵓⵙ.
ⴰⵎⴻⴷⵢⴰ:
let firstName = 'Joe';
console.log(firstName);
// Output: Joe
ⴷⴰⴳⵉ, ⴰⴹⵔⵉⵙ 'Joe'
ⵢⴻⵜⵜⵓⵏⴻⴼⴽ ⵉ ⵓⵎⴳⵉⵔⴻⴷ ⵉⵙⴻⵎ ⴰⵎⴻⵣⵡⴰⵔⵓ
.
ⵜⴰⵎⴰⵡⵜ: Ur ⵜⵜⵇⴰⴱⴰⵍ ⴰⵔⴰ ⴰⵎⵙⴻⴹⵔⵓ ⵏ ⵓⵙⵏⴻⴼⵍⵉ =
ⴷ ⵓⵎⵙⴻⴹⵔⵓ ⵏ ⵜⴻⴳⵏⵉⵜ ==
. ⴰⵎⵙⴻⴹⵔⵓ =
ⵢⴻⵜⵜⴰⴽⴷ ⴰⵣⴰⵍ, ⵎⴰ ⴷ ==
ⵢⴻⵜⵜⵡⴰⵍⵉ ⵎⴰ ⵢⴻⵍⵍⴰ ⵙⵉⵏ ⵏ ⵡⴰⵣⴰⵍⴻⵏ ⵜⵜⵡⴰⵇⴰⴷⵔⴻⵏ.
ⴰⵙⴻⴽⵛⴻⵎ ⵏ ⵢⵉⵙⴻⴼⴽⴰ ⵙⴻⴳ ⵓⵙⴻⵇⴷⴰⵛ<ⴰ ⵉⴷ="ⴰⵙⴻⴽⵛⴻⵎⵉⵙⴻⴼⴽⴰⵙⴻⴳⴰⵙⴻⵇⴷⴰⵛ"></ⴰ>
ⴰⴽⴽⴻⵏ ⴰⴷ ⵜⴻⴵⴵⴻⴹ ⴰⵙⴻⵎⵔⴻⵙ ⵏ ⵓⵙⴻⵇⴷⴰⵛ, ⵜⵣⴻⵎⵔⴻⴹ ⴰⴷ ⵜⴻⵙⵇⴻⴷⵛⴻⴹ ⵜⵉⴳⵏⴰⵜⵉⵏ ⵉ ⵓⴹⴼⴰⵔ ⵏ ⵓⵙⵎⴻⵍ ⵏ ⵓⵙⴻⵇⴷⴰⵛ. ⴷⴻⴳ JavaScript, ⴰⵢⴰ ⵢⴻⵣⵎⴻⵔ ⴰⴷ ⴷⵢⵉⵍⵉ ⵙ ⵜⴼⴻⵔⴽⵉⵜ ⴰⵙⵜⴻⵇⵙⵉ
.
ⴰⵎⴻⴷⵢⴰ:
const prompt = require('prompt');
prompt.start();
let { name } = await prompt.get(["name"]);
console.log(name);
// Input: Bob
// Output: Bob
ⵜⴰⵖⵓⵍⵜ prompt
ⵜⴻⵟⵟⴻⴼ ⴰⵙⴻⴽⵛⴻⵎ ⵙⴻⴳ ⵓⵙⴻⵇⴷⴰⵛ ⵢⴻⵔⵏⴰ ⵜⴻⵜⵜⵃⴰⴷⴰⵔⵉⵜ ⴷⴻⴳ ⵓⵎⴳⵉⵔⴻⴷ ⵉⵙⴻⵎ
.
ⵜⴰⵖⵓⵍⵜ ⵏ ⵓⴱⴻⴷⴷⴻⵍ<ⴰ ⵉⴷ="ⵜⴰⵖⵓⵍⵜ ⵏ ⵓⴱⴻⴷⴷⴻⵍ"></ⴰ>
ⵜⴰⵖⵓⵍⵜ ⵏ ⵓⵎⴳⵉⵔⴻⴷ ⵜⴻⵜⵜⴱⴻⴷⴷⵉⵍⴻⵏ ⴰⵏⴷⴰ ⴰⵔⴰ ⵢⴰⵡⴻⴹ ⴷⴰⵅⴻⵍ ⵏ ⵡⴰⵀⵉⵍ. Skop ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷ ⵙ ⵡⴰⵏⴷⴰ ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷ ⵓⵎⴳⵉⵔⴻⴷ.
ⵜⴰⵖⵓⵍⵜ ⵏ ⵓⵎⴳⵉⵔⴻⴷ ⴷⴻⴳ ⵜⵖⴰⵡⵙⵉⵡⵉⵏ<ⴰ ⵉⴷ="ⵜⴰⵖⵓⵍⵜⴰⵎⵓⵛⴰⵍⴷⴻⴳⵜⵖⵓⵍⵉⵏ"></ⴰ>
ⴷⴻⴳ ⵜⵖⴰⵡⵙⵉⵡⵉⵏ, ⵉⵎⵓⵜⵜⵉⵢⴻⵏ ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷⴻⵏ ⴷⴰⵅⴻⵍ ⵏ ⵜⵖⴰⵡⵙⴰ ⵜⵜⵡⴰⵇⴱⴰⵍⴻⵏ ⴰⵍⴰ ⴷⴰⵅⴻⵍ ⵏ ⵜⵖⴰⵡⵙⴰⵏⵏⵉ.
ⴰⵎⴻⴷⵢⴰ:
let name = 'Somebody Else';
function printFullName(firstName, lastName) {
let name = firstName + ' ' + lastName;
console.log(name);
}
printFullName('Peter', 'Henry'); // prints Peter Henry
printFullName('Lynn', 'Blake'); // prints Lynn Blake
console.log(name); // prints Somebody Else
ⴷⴰⴳⵉ, ⴰⴱⴻⴷⴷⴻⵍ ⵉⵙⴻⵎ
ⵢⴻⵍⵍⴰⵏ ⴷⴰⵅⴻⵍ ⵏ ⵜⵎⴻⵥⵍⴰ printFullName
ⵢⴻⵜⵜⵡⴰⴱⴹⴰ ⵖⴻⴼ ⵓⴱⴻⴷⴷⴻⵍ ⵉⵙⴻⵎ
ⵢⴻⵍⵍⴰⵏ ⴱⴻⵔⵔⴰⵙ.
ⴰⵃⵔⵉⵛ ⴷ ⵢⵉⵃⵔⵉⵛⴻⵏ ⵢⴻⵜⵜⵡⴰⴱⴻⴷⴷⵍⴻⵏ<ⴰ ⵉⴷ="ⴰⵃⵔⵉⵛⴷ-ⵉⵃⵔⵉⵛⴻⵏ ⵢⴻⵜⵜⵡⴰⴱⴻⴷⴷⵍⴻⵏ"></ⴰ>
Blok ⴷ ⴰⵃⵔⵉⵛ ⵏ ⵓⴹⵔⵉⵙ ⵉ ⴷⵉⵜⴻⴷⴷⵓⵏ ⵙ ⵜⵎⴻⵏⴹⴰⵡⵜ ⵏ ⵓⴹⴼⴰⵔ, ⴰⵎ ⵉⴼ
, for
, ⵏⴻⵖ ⵡⵀⵉⵍⴻ
, ⵢⴻⵔⵏⴰ ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷ ⵙ ⵜⵎⴻⵥⴷⵉⵢⵉⵏ ⵏ ⵜⵎⴻⵥⴷⵉⵢⵉⵏ {}
.
ⴰⵎⴻⴷⵢⴰ:
let total = 0;
\[1, 2, 3].forEach(function(number) {
total += number;
});
console.log(total); // Output: 6
total = 0;
for (let i = 0; i < 3; i++) {
total += (i + 1);
}
console.log(total); // Output: 6
ⴷⴻⴳ ⵙⵏⴰⵜ ⵏ ⵜⵖⴰⵡⵙⵉⵡⵉⵏⴰ, ⴰⵃⵔⵉⵛ ⵢⴻⵣⵎⴻⵔ ⴰⴷ ⵢⴰⵡⴻⴹ ⵢⴻⵔⵏⴰ ⴰⴷ ⵉⴱⴻⴷⴷⴻⵍ ⴰⴱⴻⴷⴷⴻⵍ total
ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷⴻⵏ ⴱⴻⵔⵔⴰ ⵏ ⵓⵃⵔⵉⵛ. ⵎⴰⵛⴰ, ⵉⵎⵓⵜⵜⵉⵢⴻⵏ ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷⴻⵏ ⴷⴰⵅⴻⵍ ⵏ ⵜⴼⴻⵍⵡⵉⵜ (ⴰⵎ ⵉ
ⴷ ⵓⵟⵓⵏ
) ⵓⵔ ⵣⵎⵉⵔⴻⵏ ⴰⵔⴰ ⴰⴷ ⵜⵜⵡⴰⵇⴻⴷⵛⴻⵏ ⴱⴻⵔⵔⴰ ⵏ ⵜⴼⴻⵍⵡⵉⵜ.
ⵜⵉⵡⵙⵉⵡⵉⵏ ⵏ Yimuḍan<ⴰ ⵉⴷ="ⵜⵉⵡⵙⵉⵡⵉⵏⵏ-ⵉⵎⵎⵓⵜⵜⵉⵢⴻⵏ"></ⴰ>
ⵍⵍⴰⵏ ⴽⵔⴰⴹ ⵏ ⵢⵉⴼⴻⵔⴷⵉⵙⴻⵏ ⵏ ⵢⵉⵎⴻⴹⵇⴰⵏ ⴷⴻⴳ JavaScript: var
, ⵍⴻⵜ
, ⴷ const
.
- var: Yettbeggind ⴰⴱⴻⴷⴷⴻⵍ, ⵙ ⵜⴼⴻⵔⵏⵉⵜ ⵢⴻⵜⵜⴱⴻⴷⴷⵉⵍⴻⵏⵜ ⵙ ⵡⴰⵣⴰⵍ. var
ⵢⴻⵙⵄⴰ ⴰⵃⵔⵉⵛ ⵏ ⵜⴻⵖⵍⵉⴼⵜ, ⴰⵏⴰⵎⴻⴽⵉⵙ ⵢⴻⵍⵍⴰ ⴷⴻⴳ ⵜⴻⵖⵍⵉⴼⵜ ⵉⴷⴻⴳ ⵢⴻⵜⵜⵡⴰⵙⴱⴻⴷⴷ.
var varVariable = 'I am a var variable';
- ⵍⴻⵜ: Yettbeggind ⴰⴱⴻⴷⴷⴻⵍ ⴰⴷⵉⴳⴰⵏ ⵙ ⵜⵖⴻⵔⵖⴻⵔⵜ ⵏ ⵜⴼⴻⵍⵡⵉⵜ, ⵙ ⵜⴼⴻⵔⵏⵉⵜ ⵢⴻⵜⵜⴱⴻⴷⴷⵉⵍⴻⵏⵜ ⵙ ⵡⴰⵣⴰⵍ. ⵍⴻⵜ
ⵢⴻⵜⵜⵡⴰⴼⴻⵔⵏⴻⵏ ⵖⴻⴼ var
ⵖⴻⴼ ⵍⵊⴰⵍ ⵏ ⵜⵖⴻⵔⵖⴻⵔⵜⵉⵙ ⵏ ⵜⴼⴻⵍⵡⵉⵜ.
let letVariable = 'I am a let variable';
- const: Yettbeggind ⴰⴼⴻⵔⴷⵉⵙ ⵏ ⵜⴼⴻⵍⵡⵉⵜ, ⵙ ⵢⵉⵙⴻⵎ ⵏ ⵜⵖⵓⵔⵉ ⴽⴰⵏ. ⴰⵣⴰⵍ ⵏ ⵓⵎⴳⵉⵔⴻⴷ const
ⵓⵔ ⵢⴻⵣⵎⵉⵔ ⴰⵔⴰ ⴰⴷ ⵢⴻⵜⵜⵡⴰⴱⴻⴷⴷⴻⵍ ⵙ ⵓⵄⵉⵡⴻⴷ ⵏ ⵓⵙⵏⴻⴼⵍⵉ.
const constVariable = 'I am a const variable';
ⴰⵎⴻⴷⵢⴰ ⵏ ⵓⵃⵔⵉⵛ ⵢⴻⵜⵜⵡⴰⴱⴻⴷⴷⵍⴻⵏ
let a = 5; // variable is initialized in the outer scope
for (let i = 0; i < 3; i++) {
// block scope with a for loop
a = 3; // a is accessible here, in an inner scope
let b = 5; // b is initialized in the inner scope
}
console.log(a); // Output: 3
console.log(b); // ReferenceError: b is not defined
ⴷⴻⴳ ⵓⵎⴻⴷⵢⴰⴰ, ⴰⴱⴻⴷⴷⴻⵍ ⴰ
ⵢⴻⵜⵜⵡⴰⵙⵇⴻⴷⵛⴻⴹ ⴷⴰⵅⴻⵍ ⴷ ⴱⴻⵔⵔⴰ ⵏ ⵜⴼⴻⵍⵡⵉⵜ, ⵎⴰ ⴷ ⴱ
ⵢⴻⵜⵜⵡⴰⵙⵇⴻⴷⵛⴻⴹ ⴽⴰⵏ ⴷⴰⵅⴻⵍ ⵏ ⵜⴼⴻⵍⵡⵉⵜ.
ⴰⴼⵀⴰⵎ ⵏ ⵢⵉⵎⴻⴹⵇⴰⵏ, ⵏ ⵜⵖⴻⵔⵖⴻⵔⵜ, ⴷ ⵜⵖⴰⵡⵙⵉⵡⵉⵏ ⴷ ⴰⵢⴻⵏ ⵢⴻⵍⵍⴰⵏ ⴷ ⵍⵍⵙⴰⵙ ⵉ ⵜⵉⵔⴰ ⵏ ⵡⴰⵀⵉⵍⴻⵏ ⵉⴱⴰⵏⴻⵏ ⵢⴻⵔⵏⴰ ⴷ ⵉⴳⴻⵔⵔⵣⴻⵏ. ⵙ ⵓⵙⵙⴻⵎⵔⴻⵙ ⵏ ⵢⵉⵙⴻⵎ ⴷ ⵓⵙⴻⵇⴷⴻⵛ ⵏ ⵢⵉⵎⴻⴹⵇⴰⵏ ⵙ ⵜⵖⴰⵡⵍⴰ, ⵜⵣⴻⵎⵔⴻⴹ ⴰⴷ ⴷⵜⴻⵙⵏⵓⵍⴼⵓⴹ ⴰⴽⴰⵔⴰⵎ ⴰⵔⴰ ⵢⵉⵍⵉⵏ ⴷ ⴰⵅⴻⴷⴷⵉⵎ ⵢⴻⵔⵏⴰ ⴷ ⵡⵉⵏ ⵉⵙⴻⵀⵍⴻⵏ ⵉ ⵓⵙⴼⴻⵀⴻⵎ.