Tsallaka zuwa abun ciki
Justice Tech School

Scope and Closures

Functions see variables from where they were defined. <<- assigns outside.

Example
make_counter <- function() {
  n <- 0
  function() { n <<- n + 1; n }
}
c1 <- make_counter()
c1(); c1()
print(c1())

Exercise

Assign outside.

n  n + 1

Quiz Test

What does <<- do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.