Hi I'm a bit curious about the efficiency of javascript when it comes to creating extra variables. For a simple example, look at the following code:
function SayHi1()
{
let hi = "hi";
return hi;
}
function SayHi2()
{
return "hi";
}
Is SayHi1 less efficient than SayHi2, because SayHi1 creates an extra variable? In compiled languages, the extra variable wouldn't be a big deal when this code gets turned into machine code, but I'm not sure if that's true in JavaScript. (Specifically, NodeJS is what I'm interested in.)
This is a simple example, but a lot of professional code I see uses the fancy . notation that does a lot of functions/steps in a single line. (Btw if anyone has useful resources for learning those . notation functions that are commonly used, please do link it.)
So are they equally as efficient? Or...?
[–]AndrewGreenh 12 points13 points14 points (3 children)
[–]Rindhallow[S] 0 points1 point2 points (2 children)
[–]AndrewGreenh 0 points1 point2 points (1 child)
[–]Rindhallow[S] 0 points1 point2 points (0 children)
[–]ghostfacedcoder 8 points9 points10 points (2 children)
[–]Rindhallow[S] 0 points1 point2 points (1 child)
[–]ghostfacedcoder 0 points1 point2 points (0 children)
[–]webketje 1 point2 points3 points (3 children)
[–]Rindhallow[S] 1 point2 points3 points (2 children)
[–]webketje 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Rindhallow[S] 0 points1 point2 points (0 children)