Javascript – How to simplify this ternary expression?
I wonder if there is a simpler way to write this, or is it already in it's most basic form? A ? (B && C) : B
I wonder if there is a simpler way to write this, or is it already in it's most basic form? A ? (B && C) : B
I'm just learning how to code and while studying sorting algorithms I was asked to "see if you can combine the two lines in your if and else blocks into one line to make your code look a little cleaner."…
I have been picking up JavaScript recently, and was wondering what the proper syntax would be for setting multiple variables for each outcome in a shorthand ternary. Here is an example of what I currently have, a shorthand ternary that…
I'm currently learning C#, I am a beginner, so I'm not really familiar with the particularities of this language. My problem is: I have this piece of code which is supposed to convert an INTEGER to a CHAR and add…
I'm mapping a little block of project objects for a set of footer links and I want each project name to be followed by a | EXCEPT the last one. Here's the code. const projects = [ { lastOne: false,…
I am encountering some issues with my condition to check for cart total, amongst cart quantity and shipping classes. What I am trying to achieve I am trying to hide a specific shipping method free_shipping:7 based on quantity of other…
I have a React component representing a form with inputs (Text, Number, Date). The date input has a default value - today. I use this component for two functions: creating an object and editing an object. In the first case,…
I have a simple function in component: const Button = ({text}: Props) => { const {t, ready} = useTranslation(); const [title, setTitle] = useState(''); useEffect(() => { if (ready) { const btnText = text?.length > 0 ? text : 'button.default_text';…
I am trying to reset the Session with the below code: <?= $_SESSION['pettySuccess']??''; (($_SESSION['pettySuccess']??'')=='') ?'': unset($_SESSION['pettySuccess']); ?> the idea behind my code is for the pettySuccess session to reset the session when it doesn't evaluate as ' ' but here…
Often I'm using ?? to check variables, but that will pass the left variable even if empty. I want to express (!empty($b)) ? $b : $c Close is: $b ?: $c Except that will throw a warning if $b is…