LINQ Deferred Execution: When Does This Query Read the List?
Defining a LINQ query does not always mean its results have already been calculated. Some operations wait until the sequence is enumerated.…
A fallback value can quietly change valid input. If zero is a meaningful value, using logical OR may not do what you intended. The nullish coalescing operator, ??, answers a narrower question.
console.log(0 || 10); // 10
console.log(0 ?? 10); // 0
console.log("" ?? "default"); // ""
console.log(null ?? 10); // 10
Logical OR uses the fallback for falsy values. Nullish coalescing uses it when the left value is null or undefined. MDN explains this distinction. An empty string, false or zero can therefore be preserved by ?? when those values are valid for your application.
Imagine an optional retry-count setting. If a user supplies zero to mean no retries, replacing it with a default of three changes the requested behaviour. If an empty string should be rejected, however, ?? is not a substitute for validation. Decide which values are acceptable before choosing an operator.
Write the expected result for each case and distinguish a missing value from an incorrect value. A fallback should not silently turn every invalid input into something plausible.
For a Malta frontend interview, describe what “missing” means in the feature. The useful explanation is not that one operator is always better; it is that the chosen operator preserves the behaviour you actually want.
Browse current technology vacancies with Huwell Consultancy and ask us about the responsibilities that matter to you.
Explore opportunitiesDefining a LINQ query does not always mean its results have already been calculated. Some operations wait until the sequence is enumerated.…
A C# object that implements IDisposable may own a resource that needs a clear end of use. A using statement helps express…
BigDecimal can represent decimal values precisely, but the value you pass into it still matters. A number already represented as a double…