The first way is easier to maintain. Each declaration is a single statement on a single line, so you can easily add, remove, and reorder the declarations.
With the second way, it is annoying to remove the first or last declaration because they start from the var
keyword and finish with the semicolon respectively. Every time you add a new declaration, you have to replace the semicolon in the last old line with a comma.
Related Posts:
- Define a global variable in a JavaScript function
- What’s the best way to convert a number to a string in JavaScript?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- Define a global variable in a JavaScript function
- How do you check if a variable is an array in JavaScript?
- How can I determine if a variable is ‘undefined’ or ‘null’?
- Static variables in JavaScript
- What is the difference between call and apply?
- What’s the difference between “Array()” and “[]” while declaring a JavaScript array?
- What does ${} (dollar sign and curly braces) mean in a string in Javascript?
- How can I check if an element exists in the visible DOM?
- How to interpolate variables in strings in JavaScript, without concatenation?
- How do I use this JavaScript variable in HTML?
- JavaScript check if variable exists (is defined/initialized)
- what is ScriptResource.axd in the page load in web app?
- Multiple left-hand assignment with JavaScript
- How to use Head JS with all enqueued scripts?
- How to combine javascript files without plugins?
- wp_localize_script with boolean and init
- wp_register_script multiple identifiers?
- Setting HTML properties in a Gutenberg plugin using WordPress settings
- Only loads on the contact template page
- Preloader for a WordPress Site
- Performance vs plugin genrated javascript
- How can I integrate yepnope.js with WordPress (and plugins)?
- Use one javascript variable into another javascript file
- addEventListener vs onclick
- How do I check if an array includes a value in JavaScript?
- JavaScript document.getElementById().value logs empty value
- What is console.log?
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- Copy array by value
- Compare two dates with JavaScript
- How can I merge properties of two JavaScript objects dynamically?
- In reactJS, how to copy text to clipboard?
- SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag
- Uncaught SyntaxError: Invalid or unexpected token
- JavaScript TypeError: Cannot read property ‘style’ of null
- Invalid shorthand property initializer
- nodejs – error self signed certificate in certificate chain
- Make javascript alert Yes/No Instead of Ok/Cancel
- How to create a dialog with “yes” and “no” options
- Adding images to a Bootstrap Carousel with AJAX
- XMLHttpRequest cannot load XXX No ‘Access-Control-Allow-Origin’ header
- Uncaught TypeError: Cannot read property ‘props’ of null
- How to use iMonkey in an iOS app
- ES6: Create Strings using Template Literals – Freecodecamp
- Youtube api – stop video
- Uncaught TypeError: Cannot read property ‘msie’ of undefined – jQuery tools
- Angular JS Uncaught Error: [$injector:modulerr]
- Nested objects in javascript, best practices
- classical inheritance vs prototypal inheritance in javascript
- How to measure time taken by a function to execute
- var.replace is not a function
- Uncaught TypeError: Cannot read property ‘call’ of undefined at __webpack_require__
- Async/await in componentDidMount to load in correct order
- This.props.dispatch not a function – React-Redux
- this vs $(this)
- How to open a URL in a new Tab using JavaScript or jQuery?
- How to sort an object array by date property?
- React router not showing browser history
- How to sort an array of integers correctly
- Failed to execute ‘postMessage’ on ‘DOMWindow’: https://www.youtube.com !== http://localhost:9000
- How can I check whether a radio button is selected with JavaScript?
- JavaScript button onclick not working
- What counts as CPU Intensive tasks (eg. sorting, searching etc?)
- Ajax success function
- What is the equivalent of Java’s System.out.println() in Javascript?
- How can I exit from a javascript function? [duplicate]
- Object doesn’t support property or method ‘addEventListener’
- How to fix javascript .toFixed is not a Function error
- Implementing Isomorphic JavaScript (React JS) in WordPress?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- TinyMCE in a div / textarea on frontend?
- Include Javascript as Plain (No file inclusion)
- Adding wp_ajax to a theme outside functions.php (on specific template page)
- Insert shortcode in post editor from javascript (Visual / HTML)
- WordPress problem with htmlentities
- Provide specific example for block variation
- VB.net and WordPress
- Gutenberg passing block attributes to component in ES6/ESNext
- How to add a custom.js file for a child-theme in a swift way?
- WP REST API Post Status Using JavaScript
- var is undefined in a Gutenberg block
- Custom wp.editor.initialize settings ignored
- Why my javascript code not working for the dashboard of wordpress admin?
- Got a TypeError after update and need to adapt found solution
- How to add classes and events to image in javascript using Gutenberg?
- How do you filter the list of states when country is selected? [closed]
- Prevent update_checkout from firing mid-typing
- Adding Code into Theme Customizer Header
- How to move core js files into the footer
- Suddenly extra hex string in tags
- Including Styles and JS files to work ON my plugin interface
- Gutenberg – useEffect manipulate DOM after block re-renders DOM
- Why does my array sort order changes when I pass it to JS using WP_REST_Response?
- Drodown list return issue
- Spans in gutenberg
- Get a default customizeAction text for a section using Customizer JS API
- custom page url slug needs illegal ?id=1 for javascript