Giter Club home page Giter Club logo

Comments (9)

azu avatar azu commented on July 19, 2024

switchがややこしい

最近Reduxとかでswitchを使うケースが増えたけど、使う条件はかなり限定的な気がする。
定数があって処理が1行でreturnできるものみたいな

switch(true) も普通はかかなくてもいい気はする

from js-primer.

azu avatar azu commented on July 19, 2024

ここで初めて が出てくるのかな。
JavaScriptの場合はif文だから、if式ではないというのを上手く伝える事ができると良さそう。

文の中に式は書けるが、式の中に文を書くことはできない(ホント?)とか
値を返すのが式、返さないのが文。(例外がeval 知られてそうで知られてない少し知られてるECMAScript 2015 (ES6)の新機能: Days on the Moon)

  • 仕様の中ではどういう解説なのか読む
  • 文 = ステートメント、式 = Expressionと紐付ける話

from js-primer.

azu avatar azu commented on July 19, 2024

switchがそもそもあんまり使われてなかったのは、break忘れとかdefault忘れとか、罠が多かったからというのは大きそう。
今だとLintでわかるようになっているけど。

ただ、switchの中が膨れるのは読みにくいコードの原因なので、switchの使い方としてはそういうのを触れたい。switchの下にコード続けるのはあんまりしないと思うので基本的には #20 関数と組み合わせて使うものななんだよなー。

from js-primer.

twada avatar twada commented on July 19, 2024

式の中に文を書くことはできない(ホント?)

FunctionExpression (関数式) や SequenceExpression (俗にカンマ演算子というやつ) の中に文を書けてしまいます

from js-primer.

azu avatar azu commented on July 19, 2024

そうですよね。ありがとうございます

from js-primer.

azu avatar azu commented on July 19, 2024

やっぱりここに12.14Conditional Operator ( ? : )#は入れたいな。
演算子でまとめる必要性なさそうな気がしてる。

これとifの違いを含めて、文と式の説明とするのがよさそう。

from js-primer.

azu avatar azu commented on July 19, 2024

? : 仕様的には条件演算子 になるけど、
三項演算子と言われることが多い気はする。
三項演算子って用語をメインにした方がいいのか、条件演算子をメインした方がいいのかが微妙だな。
条件演算子の方が正しいのだろうけど。

? :は条件演算子と呼びます。また <条件式> ? <真式> : <偽式> のように3つの式を使う演算子であることから三項演算子とも呼ばれます。

という感じかな

from js-primer.

azu avatar azu commented on July 19, 2024

"文字列".length ってelementsの数と言ってるのか

The number of elements in the String value represented by this String object.
ECMAScript® 2016 Language Specification

from js-primer.

azu avatar azu commented on July 19, 2024

swiftだとdefault忘れはSyntax Error

from js-primer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.