Created
March 20, 2012 13:36
-
-
Save h4/2135688 to your computer and use it in GitHub Desktop.
Работа с переменными в JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="ru-RU"> | |
<head> | |
<title>Переменные в JavaScript</title> | |
<meta charset="UTF-8"> | |
<script src="02.variables.js"></script> | |
</head> | |
<body> | |
<h1>Работа с переменными в JavaScript</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Создание переменной | |
var applesCount; | |
console.log('applesCount = ' + applesCount); | |
// Создание переменной с предопределённым значением | |
var applesType = "Gold"; | |
console.log('applesType = ' + applesType); | |
// Присвоение значения переменной | |
applesCount = 12; | |
console.log('applesCount = ' + applesCount); | |
// Присвоение значения переменной как результат вычисления | |
var message = "У меня " + applesCount + " яблок"; | |
console.log('message = ' + message); | |
// Попытка вызова несуществующей переменной | |
console.log(aliens); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Рекомендуемый способ записи переменных | |
Все переменные инициализируются в начале скрипта, | |
в виде перечисления | |
Обратите внимание на отступ перед второй и третьей переменной | |
*/ | |
var applesCount, | |
applesType = "Gold", | |
message; | |
console.log('applesCount = ' + applesCount); | |
console.log('applesType = ' + applesType); | |
applesCount = 12; | |
console.log('applesCount = ' + applesCount); | |
message = "У меня " + applesCount + " яблок"; | |
console.log('message = ' + message); | |
console.log(aliens); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Допустимые имена переменных | |
var horse, | |
Elephant, | |
anotherElephant, | |
ROBOT, | |
bab_value_123; | |
// Недопустимые имена переменных | |
var 2nd_string, | |
my-Script, | |
new, | |
счётчик; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment