Skip to content

Chapter 2: JavaScript: Unique Parts #37

Description

@valeryi

Global Declaration: Global Scope

"In JavaScript, variables can be declared without using any operators"

The above statement is correct saying only about the "non-strict" mode. In the strict mode "use strict" would cause a ReferenceError.

Declaration with let: Block Scope

function scope3(print) {
    if(print) {
        let insideIf = '12';
    }
    console.log(insideIf)
}

scope3(true);

In the snippet above there would be a ReferenceError because as the title says let (and const) are Block Scoped variables.

Truthy/Falsy Check

"Here are commonly used expressions that evaluate to true:"

  • true
  • Any number other than 0
  • Non-empty strings
  • Non-empty object

Objects in JavaScript even if it's empty will always give the truthy result. Hence the last statement in the list is not correct.
I suppose it would be better to say:object (any object)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions