Cover photo

⑥3: Booleans

Booleans

真偽値

Great work! So far you've stored numbers inside of variables. Well, surprise, there's more types of values we can store inside variables!

素晴らしい仕事です!これまでは変数の中に数字を格納してきました。驚くべきことに、変数の中に格納できる値の種類が更にあります!

.

We can also store a boolean. Weird name, huh? Don't worry, a boolean is actually quite simple. It can only be one of two values: true or false. Let's store a false value:

私たちはブーリアン(真偽値)も格納することができます。変な名前ですが、心配しないでください。ブーリアンは実際には非常に単純です。2つの値のみを持つことができます:trueまたはfalse。ではfalseの値を格納してみましょう:

.

const loggedIn = false;

.

Is the user logged in the above line? The false value indicates that they are not.

Let's store a true value:

上記のコードでは、ユーザーはログインしているでしょうか?falseの値は彼らがログインしていないことを示しています。trueの値を保存しましょう。

.

const purchasedItem = true;

.

Did the user purchase the item? Yup!

ユーザーはアイテムを購入しましたか?はい!

.

Notice that variables in JavaScript tend to be lowerCamelCase.

JavaScriptの変数はlowerCamelCaseになることに注意してください。

(ラクダの背中のように変数を命名する際ところどころが大文字や小文字になる命名規則をCamelCaseという。詳細はDetailを参照)

.

Your Goal: Create two boolean variables

目標:2つのブーリアン変数を作成します

.

Create two boolean variables a and b. Store true in one and false in the other.

aとbの2つのブーリアン変数を作成します。1つにはtrue、もう1つにはfalseを格納します。

.

.

<Details>

Casing

大文字

.

.

JavaScript variables tend to be written in lowerCamelCase. Let's take a look at an example:

JavaScriptの変数はlowerCamelCaseで書かれることが多いです。例を見てみましょう。

.

const isLoggedIn = true;

.

In this case isLoggedIn is three words. The first word is not capitalized. The next two words are combined and the first letter is capitalized. This is what I mean when I say lowerCamelCase. Other languages use different casing styles. Python and Ruby use snake case, for example (is_logged_in).

この場合、isLoggedInは3つの単語です。最初の単語は大文字ではありません。次の2つの単語を結合し、最初の文字を大文字にします。これが私がlowerCamelCaseと言っている意味です。他の言語では異なる大文字スタイルを使用します。たとえば、PythonやRubyではsnake case(is_logged_in)を使用します。

.

In JavaScript the casing is purely stylistic. JavaScript itself doesn't enforce any type of rule. All JavaScript cares about is that variables are one word (not separated by a space) and that they only include valid characters. Valid characters for variable names are a-z, A-Z, $, _ and 0-9 (although it should be noted they cannot start with a digit).

JavaScriptでは、大文字は完全にスタイリスティックです。JavaScript自体はどのようなルールも強要しません。JavaScriptが気にすることは、変数が1つの単語(スペースで区切られていない)であり、有効な文字のみを含むことだけです。変数名に有効な文字はa-z、A-Z、$、_、0-9です(ただし、数字で始まってはいけないことに注意してください)。

.

You also might see one other type of casing in JavaScript, upper snake case:

JavaScriptでは、他の一種類の大文字スタイルも見ることができます。これはアッパースネークケースと呼ばれます。

.

const SERVER_KEY_VALUE = "abcdefg";

.

This casing is typically reserved for environment variables or values that are determined before the program's execution. Environment variables store values that will configure your program to run a certain way. Perhaps you have some secret key that you don't want to store on your local machine, but you want to store on a server. You might keep that variable tucked away on the server in an environment variable that will require permissions to access or change. These are the types of variables you'll often see with this casing.

この大文字スタイルは、通常はプログラム実行前に決定される環境変数や値に使用されます。環境変数は、プログラムを特定の方法で実行するための値を格納します。ローカルマシンに格納したくない秘密鍵がある場合は、サーバーに格納したいかもしれません。その場合、その変数をサーバー上の環境変数に隠し、アクセスまたは変更するために承認が必要になるようにすることができます。これらは、この大文字スタイルでよく見られる変数のタイプです。

.

.

.

NEXT⇒⇒

https://mirror.xyz/0x1E768F62Ab8678af5c977Ee880eC8012e1ce3c4F/80uDU5BOxSoOm58rg0SpiZa_xHDQd4V63Fy-GgN9ODs