r/Clojurescript • • Oct 28 '17

Function Hoisting in ClojureScript

I'm relatively new to Clojure/ClojureScript, and I was playing around in this online ClojureScript editor (http://app.klipse.tech/) when I realized that this code worked and printed to the console:

(myFunc)

(defn myFunc [] (println "hello hello"))

I'm just wondering why it knows what myFunc is before it's defined. Is is a part of Clojure or a part of JavaScript? Would this code work in JVM clojure?

5 Upvotes

5 comments sorted by

View all comments

Show parent comment

2

u/grav Nov 01 '17

Order probably matters less in functional languages in general. But Clojure is also a very dynamic language, which has its pros and cons.

defs are a kind of mutable state of your namespace, and mutable state always messes stuff up. Having as little as possible, and understanding the nature of the little you have, is the advice I'd give :-)