Tag: brackets

JavaScript: comma after opening bracket of parameter in syntax example

The syntax for methods such as Array.prototype.indexOf() look like this: arr.indexOf(searchElement[, fromIndex = 0]) What does [, …] mean, and why is the comma inside of the brackets?

Why () are needed in this Javascript code block?

I understand there are many pitfall in javascript, but I still don’t understand there are any difference between expression a&1 and (a&1) ?? the following code tries covert 11 (10 base) to a string 1101 (2 base) <script> var str = ”; var a = 11; for(var i=0;a;i++){ str = a & 1 + str; […]

Fix Sublime Text 2 brackets matching with > 28 if()-tests?

My Sublime Text 2 Editor is not automatically matching (curly) brackets when there are more than 28 if() statements inside or 28 {} pairs. When reducing the number to <28, it magically matches brackets again as you can see below. I suspect that ST2 is by default no longer matching once a No. of elements […]

get all inner brackets/parentheses

I’m working on getting all inner parentheses of a string in JavaScript. For example if I have a string like that (don’t bother about % signs, Qx values are surrounded with it) ((!%Q1% || %Q2%) || ((%Q3% && %Q4%) || (%Q5% && %Q6%))) I would like to get in my result: (!%Q1% || %Q2%) || […]

JavaScript regex get all numbers but exclude all between brackets

I have string: 123 df456 555 [ 789 ] [abc 1011 def ] [ ghi 1213] [jkl mno 1415 pqr] 161718 jkl 1920 I need to get only numbers, that don’t placed between square brackets [ ]. All the resulted numbers I need to place inside square brackets [ ] The correct result should be: […]

Curly Brakets in Es2015

This question already has an answer here: Where can I get info on the object parameter syntax for javascript functions? 1 answer

Understanding the Context of Curly Brackets '{}'

I have been reviewing other people’s code and while ES2015 on the whole is taking some getting use to, however, I keep on getting stuck with Destructuring. Previously, In Javascript, the Curly Brackets {} were either used for blocks or objects. e.g. // Curly Brackets Block If () { … } // Curly Brackets in […]

Curly Brackets in Arrow Functions

Would someone please explain the following: Im following Dan Abramov’s lectures & doing the exercises. The code works fine, however the tests are failed when the following particular function is written with curly brackets **{ }**. case ‘toggleTodo’ : return ( state.map( (one) => { oneTodo( one, action ) }) ); The same code works […]

use brackets in checkbox name when using php and javascript?

i have a form with checkboxes like this: <input type=”checkbox” name=”type[]” value=”1″ />Fast Food<br> <input type=”checkbox” name=”type[]” value=”2″ />Table Service<br> <input type=”checkbox” name=”type[]” value=”3″ />Cafeteria<br> when i use the brackets in the name (type[]), my php works: $type=$_POST[‘type’]; echo “types are:”; for ( $counter = 0; $counter < sizeof($type); $counter += 1) { echo “<br>”.$type[$counter]; […]

Mismatched parentheses: a quick way to find them?

I just rearranged a very large JavaScript file. I now get “Unexpected end of input.” Somewhere in those hundred of functions, one has lost (or gained) a bracket. What’s the quickest way to find it?