GithubHelp home page GithubHelp logo

phase-0-pac-1-the-variable-lookup-expression's Introduction

The Variable Lookup Expression

Learning Goals

  • Define the Variable Lookup Expression

Introduction

The final of our essential three expressions is the variable lookup expression. Like the constant expression, it is boring yet profound. Once we've assigned a value to a variable name using the assignment expression, we can use the variable lookup expression to retrieve that value. Using our metaphors from the previous lesson, it looks up the variable's definition in the dictionary, or "shakes out" the value that was put in the labeled box.

Define the Variable Lookup Expression

To look up the value in a variable we simply type the variable's name in.

// Assignment expression that returns 32
age = 32;

// Type in the assigned name
age;

In return, we get 32. Try this out on your own in the below REPL console. Remember, the more you try things out, the more it will start to make sense!

<iframe height="400px" width="100%" src="https://replit.com/@lizbur10/Sandbox?lite=1&outputonly=1" scrolling="no" frameborder="no" allowtransparency="true" allowfullscreen="true" sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-modals"></iframe>

That's it. The values we associate with the assignment expression can be retrieved by simply typing the variable's name.

Variable Lookup as Conversation

In the previous lesson, we talked about a parent and a baby. A parent repeats their name hundreds of times to get the baby to assign their face to the variable ma-ma. When the baby first sees that face again and says "ma-ma!" the parent has successfully taught the child "variable lookup." Although there are no pages in baby journals for "Baby's First Variable Lookup."

Successful Lookup

If you think about it, most of childhood education until early elementary school is giving them thousands of assignment expressions so they can participate in the world: "Red," "one," "eleven," "far."

Consider this scenario. Look for the essential three expressions in here.

Parent: See the doggie? That's a doggie.
Child: Doggie?
Parent: That's right, that's a doggie. Doggies say "Woof-woof!"
Child: Doggie?
Parent: Right. Doggie.

Some time later...

Child: Doggie!
Parent: That's right. Doggie!

Let's compare teaching a baby a four-legged animal's name and teaching JavaScript that a is 4.

Expression Real-Life Conversation JavaScript Conversation
Constant Expression Parent points to the doggie 4 (evaluates to 4)
Assignment Expression Parent teaches child that "Doggie" = Puppy picture a = 4 (evaluates to 4)
Variable Lookup Child sees the dog and says "Doggie!" a (evaluates to 4)

Conclusion

Now that the essential three expressions are under your control, we're going to start rapidly building up the richness of things you can do using expressions. Whole programming languages are built around executing through evaluating expressions! Languages that work this way are called "functional languages" and they are some of the first programming languages ever created.

phase-0-pac-1-the-variable-lookup-expression's People

Contributors

lizbur10 avatar graciemcguire avatar maxwellbenton avatar ihollander avatar

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.