The proper test is:
if (capital != null && capital.length < 1) {
This ensures that capital
is always non null, when you perform the length check.
Also, as the comments suggest, capital
is null
because you never initialize it.
Related Posts:
- JavaScript null check
- JavaScript null check
- How do I check for null values in JavaScript?
- How to resolve TypeError: Cannot convert undefined or null to object
- How can I determine if a variable is ‘undefined’ or ‘null’?
- How can I check for an empty/undefined/null string in JavaScript?
- What is the difference between null and undefined in JavaScript?
- Origin null is not allowed by Access-Control-Allow-Origin
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- How to check for an undefined or null variable in JavaScript?
- Failed to load resource: the server responded with a status of 404 (Not Found)
- What is NODE_ENV and how to use it in Express?
- How to deal with net::ERR_SSL_PROTOCOL_ERROR?
- What is the way of declaring an array in JavaScript?
- How to disable JavaScript in Chrome Developer Tools?
- Reactjs – Form input validation
- What is event bubbling and capturing?
- JavaScript “Uncaught TypeError: object is not a function” associativity question
- Angular: mat-form-field must contain a MatFormFieldControl
- JS – ReferenceError: fetch is not defined
- Check if a variable is a string in JavaScript
- How can I add a key/value pair to a JavaScript object?
- Adding an onclick event to a div element
- Typescript : Property does not exist on type ‘object’
- AngularJS : Factory and Service?
- What’s the difference between console.dir and console.log?
- Use images like checkboxes
- What is the difference between document.location.href and document.location?
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Preloading images with JavaScript
- How to print elements from array with javascript
- What is the JavaScript version of sleep()?
- How do I scroll to an element using JavaScript?
- How do I set/unset a cookie with jQuery?
- Calling onclick on a radiobutton list using javascript
- How to properly export an ES6 class in Node 4?
- Uncaught Typeerror: cannot read property ‘innerHTML’ of null
- Sorting HTML table with JavaScript
- Relation between CommonJS, AMD and RequireJS?
- How to loop through an array containing objects and access their properties
- Expected linebreaks to be ‘LF’ but found ‘CRLF’ linebreak-style
- Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
- TypeError: Invalid attempt to spread non-iterable instance
- Declaring multiple variables in JavaScript
- jQuery explode string like PHP
- Call Javascript function from URL/address bar
- Anagrams finder in javascript
- Validate date in dd/mm/yyyy format using JQuery Validate
- CSS Animation onClick
- Partial render in HTML/JavaScript
- How can I use webpack with express?
- JavaScript check if variable exists (is defined/initialized)
- Embedding instagram webpage inside an iframe
- Do something if screen width is less than 960 px
- How to add a keyboard listener to my onClick handler?
- GulpUglifyError:Unable to minify JavaScript
- Javascript – Replace html using innerHTML
- Syntax error: Illegal return statement in JavaScript
- Error: TypeError: $(…).dialog is not a function
- Bootstrap modal – close modal when “call to action” button is clicked
- Javascript: difference between a statement and an expression?
- Keep getting a “Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup” when attempting to google plus login on my web app
- “NS_ERROR_DOM_BAD_URI: Access to restricted URI denied”
- How can I unset a JavaScript variable?
- D3.js: what is ‘g’ in .append(“g”) D3.js code?
- Correct modification of state arrays in React.js
- Angular 2 Sort table columns
- JavaScript string encryption and decryption?
- How to dequeue a script?
- How to use wp_localize_script in custom page template?
- Combine enqueue js without affecting dependencies
- Force core to use .dev JavaScript files
- WP Customizer set a value via javascript (to create presets)
- TinyMCE Button to Insert Multiple Lines of Text?
- preserve url parameters from affliliate sites
- How to overwrite JS variable with wp_localize _script?
- Add javascript to a woocommerce page template
- How to get value of selected page template in Gutenberg editor?
- What javascript libs & frameworks are integrated in WordPress vanilla?
- Conditional fields in contact form 7 not working
- How to place script in footer?
- Enqueueing a script and a style sheet not working
- AngularJS with route and JSON API
- Uppload image from another source wp.media
- Use onfocus event in Contact Form 7
- Get Block Attributes in JSON REST API
- How to open the add media dialogue it in a certain state / tab?
- enqueue script won’t work (enqueue style does work)
- Variable equals another variable and then equals another variable
- in jquery read a multidimensional array via wp_localize_script()
- Custom JS on a specific page
- How to get file object from file_attachment?
- How do I load urls from an external .js file to my admin head?
- Nothing in dashboard that uses javascript works
- Where is the Javascript attribute window._wpCustomHeaderSettings defined?
- How to execute WP shortcode in a javascript string “”
- how to include js in widget?
- JS files landing on page but not working, using childtheme of twentyeleven
- PHP or JS for header image rotator?
- Replacing & in JS code on pages