Upon encountering this function within the codebase (which is compiled with webpack), my curiosity was piqued and I wanted to delve into its workings.
Initially, my eyes fell upon t.length > 100
. If it's greater than 100, then the next condition is evaluated. However, this subsequent condition involves the use of ,
signs which left me puzzled about their purpose.
This snippet unfolds into two distinct parts:
$(this).val(t.substring(0, 99))
,
e = $(this).val().length
I presume that this is somewhat like a bundled code segment executed as part of a conditional statement without impacting the return value?
function() {
const t = $(this).val();
let e = t.length;
t.length > 100 &&
(
$(this).val(t.substring(0, 99)),
e = $(this).val().length
),
$(this).is("input:text")
? $(".limit_text:visible").text(e)
: $(".limit_description:visible").text(e)
}
Considering this, would both codes achieve the same outcome?
function() {
const t = $(this).val();
let e = t.length;
if (t.length > 100) {
$(this).val(t.substring(0, 99));
e = $(this).val().length
}
$(this).is("input:text")
? $(".limit_text:visible").text(e)
: $(".limit_description:visible").text(e)
}
Hence, is ,
equivalent to ;
in this context?