Recent Entries 3
- snippet critical 112d agoHow can I convert a string to boolean in JavaScript?Can I convert a string representing a boolean value (e.g., 'true', 'false') into an intrinsic type in JavaScript? I have a hidden form in HTML that is updated based on a user's selection within a list. This form contains some fields which represent boolean values and are dynamically populated with an intrinsic boolean value. However, once this value is placed into the hidden input field it becomes a string. The only way I could find to determine the field's boolean value, once it was converted into a string, was to depend upon the literal value of its string representation. ``` var myValue = document.myForm.IS_TRUE.value; var isTrueSet = myValue == 'true'; ``` Is there a better way to accomplish this?
- pattern critical 112d agoPython `if x is not None` or `if not x is None`?I've always thought of the `if not x is None` version to be more clear, but Google's style guide and PEP-8 both use `if x is not None`. Are there any minor performance differences (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?* *I'm referring to any singleton, rather than just `None`. ...to compare singletons like None. Use is or is not.
- pattern critical 112d agoPython `if x is not None` or `if not x is None`?I've always thought of the `if not x is None` version to be more clear, but Google's style guide and PEP-8 both use `if x is not None`. Are there any minor performance differences (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?* *I'm referring to any singleton, rather than just `None`. ...to compare singletons like None. Use is or is not.