Creating Pascal's Triangle when specified number of rows Does anyone have any tips on how I could improve my code



function pascal(row){
 for(var k = 0; k&lt;=row; k++){
  var pascalRow = [1];
  for(var i = 1; i&lt;=k; i++){
   pascalRow.push(pascalRow[i-1]*(k+1-i)/i)
  }
  console.log(pascalRow)
 }
}
pascal(/*Insert # of rows here */)
Nine line code review.

Apart from some style and layout issues your code is good. 

Style


If you are to use var to declare variable you should put them at the top of the function. Or you can use let which defines block scoped variables and you put them where you need them. Block scope means that the variable is only available inside the block it is declared for.
Put spaces between operators +, -, =, /, *, ===, &lt;= etc. as it becomes very hard to read code when numbers and variables are all one continuous string. Making code more readable makes it easier to spot bugs.
Don't repeat, and use contextual information to reduce name size. For example, you had pascalRow which is a little too much information in a function that is called pascal, row holds the same information regarding what the variable references.
The function name however does not give much information about what it does and is a rather bad name. Maybe pascalsTriangle would be clearer. 
The argument row is singular, the custom is a plural for counts though rows would imply an array so something like numberRows or rowCount would be more fitting
The custom for loop variable names are i then j, then k with i as the outer loop and then inner. Loop variable names and position is not a biggy in the book of buggy, bad, code; consistency is very important. Using the idiomatic styles helps you stay consistent.
Javascript has automatic semicolon insertion (ASI). The rule is only use ASI when you can list off the top of your head every way it can break your code. Add the semicolon- it will save you a ton of WTF bug hunting.
I assume you are a beginner, and to help improve your code you should always add the compiler/interpreter directive "use strict"; as the first line of any JS file or script tag. It will catch may common mistakes with an error and save you from some of the hardest to catch bugs. It will also run the code faster.


Rewrite.

So with the above in mind, here are two rewrites. The first uses var 

"use strict";
function pascalsTriangle(rowCount) {
    var i, j, row;
    for (i = 0; i &lt;= rowCount; i++) {
        row = [1];
        for (j = 1; j &lt;= i; j++) {
            row.push(row[j - 1] * (i + 1 - j) / j);
        }
        console.log(row);
    }
}


The version using let and const:

"use strict";
function pascalsTriangle(rowCount) {
    for (let i = 0; i &lt;= rowCount; i++) {
        const row = [1];
        for (let j = 1; j &lt;= i; j++) {
            row.push(row[j - 1] * (i + 1 - j) / j);
        }
        console.log(row);
    }
}


Improve?

Good coders are always trying to find ways to improve the code and the app. Here are some simple improvements to both the algorithm and output. This is meant just as an example and to introduce some new syntax.

Optimise

You may notice that each row is mirrored so you can save some computation by only doing half the row. Reversing an array (simple in Javascript) is not always the best option. Using two arrays for the left and right sides reduces the work done under the hood. For even rows you need to remove the duplicate center number.

Safeguard

If abused, your function can block a page and likely crash it when memory runs out. 

The argument for the number of rows can have have any value. Generally you would vet such a value, making sure its a number, and that the number is not too big. Takes a long time and a lot of memory to compute pascalsTriangle(Infinity)

So a simple argument check at the start check for a number and sets an upper triangle size. For bad numbers the count defaults to 10, and the max count is 40.

User friendly

Console is not a nice output, its slow and the formatting is not always what you want (And its is even worse when the in-page console is used). It would be better to create the triangle as a string and output the result after the computation is complete so that you can use the complete triangle to help set out the numbers.



"use strict";

function pascalsTriangle(rowCount) {
    const tri = []; // Hold all rows
    rowCount = Math.min(40, isNaN(rowCount) ? 10 : rowCount);
    for (let i = 0; i &lt;= rowCount; i++) {

        // arrays for left and right sides
        const left = [1];
        const right = [1];
        for (let j = 1; j &lt;= i / 2; j++) {  // only do half a row
           const val = left[j - 1] * (i + 1 - j) / j;         
           left.push(val);
           right.unshift(val);
        }
        if (i % 2 === 0) { right.shift() } // remove extra num for even rows

        // concat the two arrays and join the result as a string push to the tri
        tri.push([...left, ...right].join(" : "));
   }

  
  // Display as triangle
  const maxLen = tri[tri.length - 1].length;
  tri.forEach(row =&gt; {
      const pad = ((maxLen - row.length) / 2);
      display.innerHTML += row.padStart(row.length + pad, " ") + "&lt;br&gt;";
  });
   
}


pascalsTriangle(12)
&lt;code id="display" style="white-space: pre-wrap;font-size:x-small;"&gt;&lt;/code&gt;