> What are 'dynamic objects' and what is the way that 'C++ simple cannot do thing'?
This is the foremost proof that knowing C++ doesn't mean you know anything about JS.
JS objects are dynamic with the ability to add/remove class properties and methods or to dynamically change what class/object it inherits from all as the program executes. C++ classes are static and determined at compile time.
> Most programmers learn javascript before C++ because it's so easy to try things out in a web browser.
Most C++ programmers started programming C++ long before JS became popular. Most people who "know JS" don't actually know the language to any meaningful degree. I'm not talking about subtle things like the difference between `-0 === 0` and `Object.is(-0, 0)` or why you might use `x === x`. I mean that most can't tell me what a closure is, why you'd want to use one, or even how to use it in something like a factory. For the record, this question isn't even JS-specific, but applies to Ruby, Python, Lua, PHP, the ML family, Rust (actually just a ML with C-like syntax), Erlang, most lisps, etc.
> Where do these ideas come from? Every modern language has elements that were originally considered "functional".
JS is multi-paradigm offering imperative, OOP, and functional approaches, but because its functions inherited heavily from Scheme (I really wish Eich could have implemented scheme), it gets a lot of really nice properties.
Consider the following code (leaning heavily into the point-free side for sake of illustration)
let prop = key => obj => obj[key]
let map = fn => arr => arr.map(fn)
let filter = fn => arr => arr.filter(fn)
let reduce = fn => arr => arr.reduce(fn)
let sum = (acc, x) => acc + x
let pipe = (...fns) => val => fns.reduce((acc, fn) => fn(acc), val)
let data = [
{
fname: "John",
lname: "Doe",
age: 41,
sex: 'M',
children: [
{fname: "Fred", lname: "Doe", age: 11},
{fname: "Jill", lname: "Doe", age: 8},
{fname: "Elliot", lname: "Doe", age: 3},
]
}
]
let printSumOfChildenAgeOfMiddleAgedFathers = pipe(
filter(x => x.sex === 'M' && x.age > 40), //get all males over 40
map( //for each male
pipe(
prop('children'), //get their children and age
map(prop('age')),
reduce(sum), //add ages together for father
)
),
reduce(sum), //add ages for all fathers
)
Sure, it is pointless code off the top of my head to illustrate my point (though with some changes it could be actual code I've seen). If you'd like to counter, write this functional-style code in C++ without changing to imperative code. It'll be 10x as long and an unreadable mess.
> Even labeling someone as a "C++ dev" or "javascript dev" is a giant red flag of inexperience.
I consider language design as a bit of a hobby and I've spent time with a LOT of very different languages. Even so, I only consider myself proficient in a handful of them. Even setting aside the impossible task of learning all those standard libraries completely (even most experienced Java or C# devs don't actually know the entire standard library of those behemoths), just learning the warts and weird edge cases of almost any language you can name takes at least a couple years and with large and/or convoluted languages (eg, C++ or JS) it can take many years.